                                      
           
                                                
                                         ,     .
                                                                  - .. 
           
             ++ -     ,    ,
                   -
           .      ++  -
               C.   ,  
            C, ++      
             .     ,   
            ,     
                .   -
                .    
               ,   .
                        ,
                  . -
                  --
           .          -
           ,      .
           
               ++  .  -  , -
            .     , -
             ,       -
           ,  ,   , -
                    
           . ++   ,   C,  -
                .       
           ,      , -
               ,  inline- ,
              ,   , -
                 .   ++  
               C        
            (,  ,  ,    ..).    
              ,  .
           
             ++            ,  
            .      
                  ,   C.   ++
              C ,    ++   -
                ,   -
             C.
           
                    ,    
                    -
            .       ++,    
             .
           
                
           
             ++       , -
                    . 
           ,   ,   ,   ,  ,
            ,   ,   ,   , 
           ,          
           .         
           /.
           
              ,   ++     , 
                 ,    -
           ,     ,   .  
                :   ,   ,  
           ,   ,  ,  ,   
            .
           
                    ,   ,  
           ,   ,   ,   ,   ,
                 ++,     Bell
           Labs, , , 26-27  1985 .
           
                                  ,    
                                   
           
                                         " ," -  ,  - "
                                                             ."
                                                                  - . 
           
                    ,    
                ++  . -
              ++, ,    
           ++,       ++.    -
            :       
           ,       ++.
                  
           
              1 -       ++,  -
             ,     . -
             C         ,
               ,    C  ++.  
                    ++,  
                  ,   
            2, 3  4.
           
               2, 3  4   ++,    -
             :   ,    
            ++ .   ,     
           ++,      C.    -
             ,       
             .
           
               5,  6  7   ++    -
           ,   ,     C.   5 -
              ,   ,   -
             ,   ,  
            ,  ,  .   6 ,   -
                   ,
               ,  -
           ,      ,       
             ,      
             .    7        
           ,            
               ,      
                        
           ,             
           .
           
               8   ostream  istream,  
               -.    
             :      ,   -
                ++.
           
             , ,       ++.
           
                      #2.3.4 (
           2    3.4).     -    
           #.8.5.5.
           
                  
           
                       ++  
              *.   
            ,      -
              UNIX  AT&T 3B,  DEC VAX,  IBM 370  Motorolla 68000.
            ,        ,    -
               ,     3B 
           UNIX System V  2 [15], VAX11/750  8-  UNIX [16]
            CCI Power 6/32  BSD4.2 UNIX [17].  ,    -
           ,  -  " ++",      
              "" (  #.15.3), -
                C  ++.
           
           
           * ++    AT&T, Software Sales and Marketing, PO Box
           25000, Greensboro, NC 27420, USA ( 800-828-UNIX)   
            ,     UNIX.  (.
           )
                
           
                 .    
            -.      ,
                           
             .       
           ,        .  
           ,      (*1)  
            ,    (*2)    ,  
           (*3) - .  ,     ,    -
            ,      ,  
            .   (*1)   ,   -
           ,   ,      -
             .    , ,    -
                ,     (*5)
            .        2-4  -
                C.     .  [1]   -
                      
            .        
            5-7.   ,      , -
              ,     .  -
                  ++  -
           .
           
                   
           
                    .  ,
                      
              ,   . 
                C,    
            C.
           
              ++           
            .    ,  ,    
                 .   -
              ,       .
              ,  ,      ++ -
               - . 
            ,  ,   -
               ,    -
           .
           
                ,        
               . ,   , 
                   "" -
           ,   .     ,
                 16- ,     
           32- .
           
             ++       -
               ,     C  
           UNIX.       -
           ,          
           ,     ++.    ++
              .      
           ++  ,       . -
            ,   ,    -
                       -
             .
           
                    ++    
                   
             .          
             .       -
               ,        
                .
                 
           
             , ++     C [7].  C  
           ,     C      
             ,        
            . C,   ,   -
             BCPL [9].   ,  // ()
             ++  BCPL.     BCPL,    ,  
           ++  -  VALOF .     
             Simula67 [2,3],     
             (       ).  
            ,      
            .   ++     -
               ,    ,
             68 [14].
           
              ++ -    ( 1983-). 
                 1980-      -
             "C  ".      ,
                     
              Simula67,       .
           "C  "     ,  
                , -
            ()        -
           .    "C   "    ,  ,
               .  ++       
                   1983.  
              ++    .
           
              ++   .    -
                 C.  "++" -   
            C.      C+     ,
            ,         .
             C ,  ++ ,  ++C.  D 
            ,     C     
                   -
           .      ++    -
              [8].
           
              ++  ,       -
                ,  C   
             .       
                    
           .    ++     . -
           ,      . ,
             ++    ++.     
           "  ++"   "   ++".   ++ -
                 ,    -
             ,    ,  -
                    .
                  ++   C,   
           
               [1] ,     ,
           
               [2]     ,
           
               [3]      
           
               [4]     UNIX.
           
              C   ,       
             ,   C  .  ,   C
            "C  "   (,  ) -
                     C  Simula--
            .
           
             ++    ,     ,   ,
               C,    -
           ,         ,   
             C.  ,         
            C       (., , 
           [12]).    ,  
           
               [1]     C,      
                    ++  ,         -
                    C  ++,
           
               [2]            
                 ,   C,     
                    ++  ,  ++    C 
                       C,
           
               [3]    ,    C,  -
                  , ,      -
                   ++,       
           
               [4]   ++    C       
                       ,      
                   ,    ,    -
                     .
           
                  ++,   -
               ,     ,     C   ++,
                   .
           
              C       ,  
              ++ (.   [11]).  -
            ANSI  C [10]     ,  -
             "C  ".       -
           .  ,   void*    ANSI C  
             ++.   ANSI    ,
              ++,     -
           . , ,   (#.11), 
            ,  ,    
           .     ,  C  ANSI C 
             ,    ++ (. #.11).
                  
           
             ++        C    
             C  .   , C -
             ++,    ,       -
              ,     
           ,      : -
           ,    .     
           new  delete,      ++   -
                   .
           
              ++         
           ,     C.   ,     -
               ,  ++     
            inline,  ,   ,   -
                 .
           
                   C      
                       
            .   ++,  
           ,          .  
            C  ++       ,  -
              . C   . ++  -
            ,     , 
                .    
           ,      , 
                    
            .       
              ,      -
              .  ,    
            ,     ,  -
              ,      ..,  
                   .
           
              ,     ++ , -
               ,    -
             C.    ( 1000 )   -
                ,     -
            .         .  
             10 000    ,    ,
                   ,    .
           ++   ,         
                ,    
                       25  000
           .       ,   ,
            ,   ,   ,     
                ,      
             .  ,      -
                  ,     
              ,    ,   -
                ,    
            .
                , ,    -
           ,     ,     ..
           ++   ,    ,   -
                   ,  
                .    -
           ,        -
            .
           
                           -
            ,   ,    ..  
              ,     -
           ,    ,    .   ,   
                   
           ,          ,  
            .
           
              -   ,    
                         
             .  ++   . ++ , -
              ,     .., 
              C ,     
           .
           
                 
           
                    :
                  ,   
            ,   ,   -
           ,    ,   .     
           ,    "  ",    -
                    -
              .      -
            C.      ,  
           "   ",        
              .      -
            ,   C   ++.
           
               ,    /,  -
             ,        ,
            .          
                  .  
               ,          
             .     -
            ,     ,   
           .  ,       
                 , 
             ,    ..    
                     
           .
           
                      -
           .  ,     ++    
            .
                    ++
           
                        
           :     ,   -
            ,    ,      -
            .        -
                     
           -         .
           
                 ,   -
                         
                .   
           ,  ,    .  - 
           ,   ,        : 
            ,       ,     
           .       . 
                    (  
           )  .      -
              ,        
             .    ,   
             :        ?
                      /  ?  
                ?     -
               ,   -,   ,
              "",         
               ,  ,   -
            "" .
           
                   ,   -
             :    , , -
              ..    ,    
            ,    ,    -
               . ++  ,     -
                ,    .
           
                    ,     
             .     
           ,          
           ,    ,         
           .  ,    ,   
           ()    .    , A  B.
             "A    B",  "A   B"
            "A   B"    ,  
             "A    B"    ( 
             -). ,  , -
             ,         "A  B 
           ...".
           
                    ,  
             ,     ,  
                   -
                       .    ++   
               .      
               (?).  ,  -
                 ,           
               .    
                   (  )
                (#7.2.8).  -
              ,    , 
               ( ).
             ,      .    -
           ,          -
            ,        
               , , "A  B  C  ...". 
           ++    ,      
           ,         -
             (#7.2.5).
           
                      
                ,    
              .     
             ,      ,   -
                .   
                   ++    
           friend  (#5.4.1).
           
                      -
             (     ),   
                ,   ,   -
           ,    ,     -
               .      
           -      -
           ,        .
           
             ,        -
             ,       ,   ,
                    -
           .   ,      ,   
               ,    -
           .
           
              "     ++"    
           "    ?"    : "-
           ,      "  ".   
           ."      ++        ,
               -      .
           
                  *
           
                  ,      -
             ++.     ,   -
                ,         
             .      -
           ,     .    
           .      ,    -
           .           , -
           !
           
           
           *     . (.
           .) [1]   ,   
                         .  
                     ,   -
                :
           
                [a]      ""  ,   
                     .
           
                [b]    ""   ,    
                       .
           
                [c]        ,  
                       .        
                         .   () 
                      ,     .
           
             [2]    ,       
                  ,      ,
                   ,   , :
           
                [a]    .
           
                [b]     ( ).
           
                [c]    -.
           
                [d]   ,     ,  
                     [a], [b]  [c].
           
                [e]       -     -
                     .
           
                [f]     " ",   
                     .
           
                [g]   inline-,     -
                      .
           
                    C
           
               -  C,     -
             ++   C,  ,  ,   
           ++.   , ,  "  C"  -
             (#.15).    ,   ++
             - ,  C.  (#define)  ++ 
                 ,     
           ,   const (#2.4.6)  enum (#2.4.7),   inline
           (#1.12) -       .  -
                   -   
               .  ,    
                     ,  
               ,     ,  - 
            ,          .    
           malloc() -  new (#3.2.6)     .  
                -   -
            (#2.5.2).
                                
           
                   ,     -
                 ,      -
           .
           
             [1] A.V.  Aho, J.E. Hopcroft, and J.D. Ulman: Data Structures and
                Algorithms. Addison-Wesley, Reading, Massachusetts. 1983.
           
             [2] O-J.  Dahl,  B.  Myrhaug,  and K. Nygaard: SIMULA Common Base
                Language. Norwegian Computer Center S-22, Oslo, Norsay. 1970
           
             [3] O-J. Dahl and C.A.R. Hoare: Hierarchical Program Construction
                in "Structured Programming." Academic Press,  New York.  1972.
                pp 174-220.
           
             [4] A.  Goldberg and D. Robson: SMALLTALK-80 The Language and Its
                Implementation. Addison-Wesley, Reading, Massachusetts. 1983.
           
             [5] R.E.  Griswold  et.al.:  The  Snobol4  Programming  Language.
                Prentice-Hall, Englewood Cliffs, New Jersey. 1970.
           
             [6] R.E.  Griswold  and  M.T.  Griswold:  The  ICON   Programming
                Language. Prentice-Hall, Englewood Cliffs, New Jersey. 1983.
           
             [7] Brian W.  Kernighan and Dennis M.  Ritchie: The C Programming
                Language.  Prentice-Hall,  Englewood Cliffs, New Jersey. 1978.
                  :  ..  ,  .  , . . 
                 . .:   . 1985.
           
             [8] George  Orwell:  1984.  Secker  and  Warburg,  London.  1949.
                 : . . 1984. ...
           
             [9] Martin   Richards  and  Colin  Whitby-Strevens:  BCPL  -  The
                Language and Its Compiler. Cambridge University Press. 1980.
           
             [10] L. Rosler (Chairman, ANSI X3J11 Language Subcommittee):
                Preliminary Draft  Proposed  Standard  -  The  C Language.  X3
                Secretariat:  Computer and Busineess  Equipment  Manufacturers
                Association,  311 First Street, N.W, Suite 500, Washington, DC
                20001, USA.
           
             [11] L.Rosler:  The Evolution of C - Past and Future.  AT&T  Bell
                Laboratories  Technical Journal.  Vol.63 No.8 Part 2.  October
                1984. pp 1685-1700.
           
             [12] Ravi  Sethi:  Uniform  Syntax  for  Type   Expressions   and
                Declarations.  Software Practice & Experience,  Vol 11 (1981),
                pp 623-628.
           
             [13] Bjarne Stroustrup:  Adding Classes  to  C:  An  Exercise  in
                Language Evolution. Software Practice & Experience, 13 (1981),
                pp 139-61.
           
             [14] P.M.  Woodward and S.G.  Bond:  Algol 68-R Users Guide.  Her
                Majesty's Stationery Office, London. 1974.
           
             [15] UNIX  System V Release 2.0 User Reference Manual.  AT&T Bell
                Laboratories, Murray Hill, New Jersey. December 1983.
           
             [16] UNIX  Time-Sharing  System:  Programmer's  Manual.  Research
                Version,  Eighth Edition. AT&T Bell Laboratories, Murray Hill,
                New Jersey. February 1985.
           
             [17] UNIX Programmer's Manual. 4.2 Berkeley Software Distribution
                University of California, Berkeley, California. March 1984.
                                                                              
                                   1   ++
           
                                            
                                   -    .
                                                            -  
           
                        
            ++.       ++,  
           ,     ,    
                 .    
                         ++:
            ,  , , ,   
           .      ++  -
             ,    ,  ,  
           ,     .
                1.1 
           
                          
           ++.          
            ++,        ,    
            .      , -
                 ,   
               .         
                ,      
                    .  
            ,     , 
           .
           
                1.1.1 
           
                  ,   ,   -
           :
           
             #include <stream.h>
           
             main() {
                 cout << "Hello, world\n";
             }
           
              #include <stream.h>  ,   
                ,    
           stream.h.      cout << "Hello,  world\n" 
             .  << (" "*)    -
              (  ,   "Hello, world\n"  -
              cout).   -   -
           ,     .     
           \,       ,    
           ,    ,  \n    . 
                Hello,  world   -
           .
           
           
           *   C <<      
           .   <<  ,       <<
              ,       -
            .   ,   #1.8. (. )
               
           
             main() { ... }
           
            ,   main.    -
               main,       -
             .
           
                1.1.2 
           
                 cout  ,   
            <<?        ++ -
              .      
            ,     ,         
            .       ,
               ,    .   
                ,   , 
              (    cout  <<).   -
           ,       
              (  ,  -
                 ).     cout  <<
              stream.h,   ,    ,   
                .  
                 
              cout  <<.    ,      
             ,       stream.h,   
                ,
             ,     .
           
                ++   CC.    
             ,     cc    C,    
              .  ,       "Hello,
           world"      hello.c,      -
                ($ -  ):
           
             $ CC hello.c
             $ a.out
             Hello,world
             $
           
             a.out -        
           .       ,    -
                -o:
           
             $ CC hello.c -o hello
             $ hello
             Hello,world
             $
                1.1.3 
           
              ( )    
            .  ,    ,   -
             .
           
             #include <stream.h>
           
             main() {
                 int inch = 0;  // inch -  cout << "inches";  cin >> inch;
                 cout << inch;  cout << " in = "; cout << inch*2.54; cout << "
                 cm\n";
             }
           
                main()    inch.  
                >> (" ")    -
              cin.  cin  >>,  , 
            <stream.h>.        -
            :
           
             $ a.out
             inches=12
             12 in = 30.48 cm
             $
           
                      .
               .      <<       
            ,         
               :
           
             cout << inch << " in = " << inch*2.54 << " cm\n";
           
                        
           .          -
            ,       , -
               -.    , -
                   ++,  "" 
           -      
             #include.  ,  ++   ,  
               ,    --
           .      ,  -
            ,   <<  >>.
                     1.2 
           
                    ,   -
                    
                 .   ++  
               .
           
              /*  ,      */.
                   
           (,  ).     
                 ,  
            ,   /* */    .
           
              //  ,       
           ,      .  ,   
             .        
            .  //    , -
              /*  */,    /*  -
            //.
                1.3   
           
                   ,    ,
               . , 
           
             int inch;
           
           ,   inch   int,   ,  inch  
           .
           
              -  ,     . 
                 .     
             .     ,  +, -,
           *  /.  ,    stream.h,   int 
               <<,    ostream.
           
                  ,      
           ,     . , 
           
             cout << inch << " in = " << inch*2.54 << " cm\n";
           
                   .
             ,    inch    -
             inch*2.54     -
                  .
           
              ++          -
            .     ++    -
           ,      .
           
                1.3.1  
           
              ,      -
            , :
           
             char short int long float double
           
                   ,  -
             -        .  
            char  ,      
            (,  ),     int  ,  -
                 (, ). -
             ,      ,  
              (sizeof).  ++     -
              char,   char     -
           .       :
           
             1 =  sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long)
             sizeof(float) <= sizeof(double)
           
              ,   -      
           .   , ,      -
           ,     .
                    const.   
           ,    ,    ,   -
           ,        const    
           .
           
             const float pi = 3.14; const char plus = '+';
           
             ,       ,    
           . ,   ,   -
           ,   .  ,  ,   -
             .    -
             .    , 
            .      -
                .
           
                       
           :
           
             + (,   )
             - (,   )
             * ()
             / ()
           
                :
           
             == ()
             != ( )
             < ()
             > ()
             <= (  )
             >= (  )
           
             ,      : 7/2  3. 
               %  : 7%2  1.
           
                    ++    
                ,    
              :
           
             double d = 1; int i = 1; d = d + i; i = d + i;
           
                1.3.2  
           
              ,      :
           
             *  
             *const   
             &  
             [] * () , 
           
           
           *  .    (, 
           ),    ,       ""
            . (. .)
             :
           
             char* p  //    char *const q //  -
                char v[10] //   10 
           
                     , 
            v  : v[0]..v[9].    #1.5, -
             #1.9.       -
            :
           
             char c;
             // ...
             p = &c; // p   c
           
              &    .
           
                1.4   
           
              ++    ,     -
                     .
                       ,  
                      ,
             .. ,    , -
                  .
                1.4.1 
           
              ++       ,     
           ,  ( )  .  ,  
           
             ~ ()
             & ()
             ^ ( )
             | ( )
             << (  )
             >> (  )
           
              ,           -
            .
           
                   .    &  
             ,   & -    .
                  :  +    
           a+b      ,     
           float,    ,     int.   #1.8 ,
                 ,   -
           ,     ,     -
            .
           
              ++     =,     ,
              .   ,     -
              , , x=sqrt(a=3*x).  
           .  a=b=c   c  b,    a.
                 ,    
               .  ,  x[i+3]*=4
            x[i+3]=x[i+3]*4,     ,  
           x[i+3]    .      -
                     
           .      .
           
                 ++   . -
             * * ,  ..  *p  , 
             p.         -
           . ,   char* p,  *p  ,  -
             p.          
               ++    --.  ,  p
               v,   p++  p   
            .
           
           
           * . dereference -   ,  
             . (. .)
                1.4.2  
           
                 - ;.      -
           ,      . :
           
             a = b*3+c; cout << "go go go"; lseek(fd,0,2);
           
                1.4.3  
           
                 :
           
             ;
           
                .         ,
               ,     .
           
                1.4.4 
           
              -     ,     -
            :
           
             { a=b+2; b++; }
           
                 . 
            ,    ,     .
                       
            .
           
                1.4.5  if
           
                    
                .  ,   
              ,   i     c  
           :
           
             #include <stream.h>
           
             main() {
                 const float fac = 2.54; float x, in, cm; char ch = 0;
           
                 cout << " : "; cin >> x >> ch;
           
                 if (ch == 'i') { // inch -  in = x; cm = x*fac;
                 }
                 else if (ch == 'c') // cm -  in = x/fac; cm = x;
                 }
                 else in = cm = 0;
           
                 cout << in << " in = " << cm << " cm\n";
             }
           
             ,         if     
            .
                1.4.6  switch
           
              switch        
           .       :
           
             switch (ch) { case 'i':
                 in = x; cm = x*fac; break;
             case 'c':
                 in = x/fac; cm = x; break;
             default:
                 in = cm = 0; break;
             }
           
              break            switch.
              case   ,   -
                   ,   -
            default.     default.
           
                1.4.7  while
           
                ,       p  
               q   .   
                0.
           
             while (p != 0) {
                 *q = *p; //  
                 q = q+1; p = p+1;
             }
             *q = 0;      //   0   
           
                while         
           .   ,      , -
                .    
            ,      .
           
                .       ++
              ,   :
           
             while (*p) *q++ = *p++;
             *q = 0;
           
             *p++ :  " ,   
           p,   p."
           
                ,     p 
              .        ,
              :
           
             while (*q++ = *p++) ;
           
                ,     p,  p ,
              ,    q,   q .
             ,   .     -
             ,      .   -
             ,    .  ++ (  C) -
                    
              *.
           
           
           *   expression-oriented (expression -  
           ). (. .)
                1.4.8  for
           
                    :
           
             for (int i=0; i<10; i++) q[i]=p[i];
           
              
           
             int i = 0; while (i<10) {
                 q[i] = p[i]; i++;
             }
           
             ,    ,   -
           ,  .    ++    
              .     for  -
                ,      .
           :
           
             for (i=0; i<10; i++) q[i]=p[i];
           
                ,  i -
              .
           
                1.4.9 
           
              -  ,    .   -
                .   -
           ,        ,  
             ()   -
           . :
           
             for (int i = 1; i<MAX; i++) { int t = v[i-1]; v[i-1] = v[i]; v[i]
                 = t;
             }
           
                    for i  
            ,  t MAX-1 .
           
                1.5 
           
              -    ,     -
                 ,  .
            ,    2:
           
             extern float pow(float, int); //pow()    
           
             main() {
                 for (int i=0; i<10; i++) cout << pow(2,i) << "\n";
             }
           
                -  , ,  pow - -
           ,       float  int   float.
               ,   
                .
                     -
                ,      
            .      -
            . ,  pow(12.3,"abcd")  -
            ,   "abcd"  ,    int.  
             pow(2,i)     2   float,   
            .  pow     :
           
             float pow(float x, int n) {
                 if (n < 0) error("sorry, negative exponent to pow()");
                              // ,    pow()
                 switch (n) { case 0:  return 1;  case 1:  return x;  default:
                 return x*pow(x,n-1); }
             }
           
                   ,   -
              (  )       -
            (  ).       
            return.
           
              ,    ,  , -
                   ,   
               .       
           ,          -
             . , ,    -
                      -
            :
           
             overload pow;  int pow(int,  int);  double  pow(double,  double);
             //... x=pow(2,10); y=pow(2.0,10.0);
           
             
           
             overload pow;
           
            ,    pow    -
              .
           
                 ,        
           void:
           
             void swap(int* p, int* q) //   {
                 int t = *p;
                 *p = *q;
                 *q = t;
             }
                1.6  
           
               ++         -
           ,      , , 
            .            
                   ,     
            . :
           
             extern double sqrt(double); extern instream cin;
           
                   
           -       ,   -
            ( ) ,    ,    -
           ,       ,    .
           ,    sqrt         
                 math.h,      
              4,  :
           
             #include <math.h>
             //...
             x = sqrt(4);
           
                     -
            ,    ,    .
           ,      inline- -
             (#1.12)        (#1.3.1).
              ,     
             .      -
             .
           
                include    ,      
           ,   <math.h>,        -
             (  /usr/include/CC),  , 
            -      ,   
            . :
           
             #include "math1.h"
             #include "/usr/bs/math2.h"
           
            math1.h     ,   math2.h
             /usr/bs.
           
                   ,  
                ,    
            .  header.h   :
           
             // header.h
           
             extern char* prog_name; extern void f();   main.c 
              :
           
             // main.c
           
             #include "header.h"
             char* prog_name = ",  "; main() {
                 f();
             }
           
             f.c  :
           
             // f.c
           
             #include <stream.h>
             #include "header.h"
             void f() {
                 cout << prog_name << "\n";
             }
           
                    :
           
             $ CC main.c f.c -o silly
             $ silly
             ,  
             $
           
                1.7 
           
              ,          
           ostream.    ,  ,   
               streambuf.   streambuf     
           <stream.h>,       ostream.
           
             ,   ,  ostream   
            .       -
            <stream.h>,     -
           .
           
              ,    (  ++ -
            class,  .. ),  ,  
              ,      
            .     :    (private)
           ,  ,     
           ,    (public) ,    
             :
           
             class ostream { streambuf* buf; int state;
             public:
                 void put(char*); void put(long); void put(double);
             }
                public:  :  
                  put().      
           public        ostream.   buf 
           state     put(),   -
            .
           
             class  ,    ,   -
            ostream,        ( ,   
              int):
           
             ostream my_out;
           
             ,  my_out    
           (,   #1.10),     :
           
             my_out.put("Hello, world\n");
           
                       -
             .    my_out   
           put().
           
                :
           
             void ostream::put(char* p) {
                 while (*p) buf.sputc(*p++);
             }
           
            sputc() - ,     streambuf. 
           ostream ,   put() ostream'   
             put().
           
                      . 
                  ,    -
              ostream::put():     buf    
           buf ,    .
           
                      
            this.      X this       X*
           (    X)      ,  
              .  ostream::put()  -
              :
           
             void ostream::put(char* p) {
                 while (*p) this->buf.sputc(*p++);
             }
           
              ->     ,   -
           .
                1.8  
           
                ostream     <<,   
                .  -
           ,   .
           
                @,    @ -    ++,  
                    
            operator@,     .
           :
           
             class ostream {
                 //...
                 ostream operator<<(char*);
             };
           
             ostream ostream::operator<<(char* p) {
                 while (*p) buf.sputc(*p++); return *this;
             }
           
              <<     ostream,   s<<p -
             s.operator<<(p),   s  ostream  p -
                   .      <<   ,      
           operator<<(char*)       .  -
           ,        this.
           
             ,         ostream,
             <<        .  ,
           s<<p<<q    (s.operator<<(p)).operator<<(q).  
                .
           
                ,      
           ostream,        <<   
           ,  complex,     ostream:
           
             ostream operator<<(ostream s, complex z)
             //  complex  :  real   imag
             //  complex  (real,imag)
             { return s << "(" << z.real << "," << z.imag << ")';
             }
           
              operator<<(ostream,complex)      -
           ,       .  
               ,      <<,    
             ++,   ,   f<<b<<c
            (a<<b)<<c.     
                   .  ,
            z -  ,   s<<z      -
               ( ) operator<<(s,z).
                1.9 
           
              ,   ostream    
               .     ,  ostream
                <<:      -
                 .    state -
              .      
             ostream    ostream.
           
                  .      
           .  T&    T.    -
           ,       ,   -
           . :
           
             ostream& s1 = my_out; ostream& s2 = cout;
           
                 s1  my_out ,   -
              . , 
           
             s1 = s2;
           
            ,    s2 ( , cout),  ,
              s1 ( ,  my_out).    
            
           
             s1.put("   ->");
           
                ,      -
           ,    :
           
             &s1 == &my_out
           
                    ,  
             ,     ,     (
                 ):
           
             ostream& operator<<(ostream& s,  complex z) { return s << "("  <<
                 z.real << "," << z.imag << ")";
             }
           
              ,      , 
                 s,    -
              ,      .       ,  
            ,    ,   -
               -  ,    -
             ,     .
           
                   ,  
                   -
           .      ,     
                 .
           
             class istream {
                 //...
                 int state; public:
                 istream& operator>>(char&);    istream&    operator>>(char*);
                 istream& operator>>(int&); istream& operator>>(long&); //...
             };
             ,    long  int    ,
                  .   ,
              ,   int     long   -
                (#.6.6),   
                       
            .
           
                1.10 
           
              ostream         .
                   ,    
               .    
              ,        ,      
           :
           
             class ostream {
                 //...
                 ostream(streambuf*); ostream(int size, char* s);
             };
           
                  .       
           streambuf   ,      
               .        
                  .   
           , ,   :
           
             ostream my_out(&some_stream_buffer);   char   xx[256];    ostream
             xx_stream(256,xx);
           
              my_out          
           -         ,            
           ostream::ostream(streambuf*),    
           &some_stream_buffer,     -
              streambuf.       
              ,     ,  
                .   
             ,       
             ,         .    
           ,    ,      
              ,       .
                1.11 
           
               ++         ,  
                   
            .    (    
           )      -
               .    ,  ,  -
           ,        ,   
                 ..     -
             :  "        ."  
           ,      .  ,
               ++,   
                ,        ,  
           ,      ,     -
           ,        .
           
             class vector { int* v; int sz;
             public:
                     vector(int); // 
                     ~vector(); // 
                 int size()  {  return  sz;   }   void   set_size(int);   int&
                 operator[](int); int& elem(int i) { return v[i]; }
             };
           
              size     ,    
                0 ...  size()-1.  set_size
               ,  elem      
              ,   operator[]    -
            .
           
                ,      
           ,      , 
                 
            new:
           
             vector::vector(int s) {
                 if (s<=0) error("bad vector size");
                               //   
                 sz = s; v = new int[s];
             }
           
                       vector   
           ,   ,    :
           
             vector v1(100); vector v2(nelem*2-4);
           
                 
           
             int& vector::operator[](int i) {
                 if(i<0 || sz<=i) error("vector index out of range");
                                      //     
                 return v[i];
             }
              ||  ()  -     .   
              ,     ,    
                     .   
            ,   []     
            :
           
             v1[x] = v2[y];
           
                    ~vector  -  ,   
           ,    ,      ,  
                   .    C
             ~C.    
           
             vector::~vector() {
                 delete v;
             }
           
             ,     delete,   ,
             ,    vector   
           ,          
            .
           
                1.12 Inline-
           
                    ,  
                 .   
                            
             ( ,      
              ),       ++    -
           ,     .     -
                    .   
                       
           inline-.      ,  -
                     .
                 .  ,  ,  size    elem
           inline-, 
           
             vector s(100);
             //...
             i = s.size(); x = elem(i-1);
           
            , 
           
             //...
             i = 100; x = s.v[i-1];
           
             ++       ,    
             ,         
             .  ,     
                ,   
           .
                ,         ,         
           inline-,       inline,  ,  
             ,            
           ,        size()  elem().
           
                 inline-   
                   .  ,  inline-
                 ,  ,
              ,     .    inline-
                    -
           ,     .
           
                1.13  
           
                ,     
              .
           
             class vec: public vector { int low, high;
             public:
                 vec(int,int); int& elem(int); int& operator[](int);
             };
           
            vec 
           
             :public vector
           
           ,   ,   vec -  vector.  ,  vec
            ()    vector   , 
              .  ,   vector  
               vec,    vec ,      
           vector.
           
              vec   vector ,      -
            ,       -
             ,    ,        
             elem(int)  operator[](int).   elem() 
           vec    elem()  vector:
           
             int& vec::elem(int i) {
                 return vector::elem(i-low);
             }
           
                 ::     ,
                    vec::elem()  
           .     ::    
           .      vec::elem()  inline,  ,
            ,  ,  , -
                ,     -
              v  vector.     
                          
           .
                :
           
             vec::vec(int lb, int hb) : (hb-lb+1) {
                 if (hb-lb<0) hb = lb; low = lb; high = hb;
             }
           
             : (hb-lb+1)      
              vector::vector().   -
              vec::vec().   ,  -
            ,       -
            vector:
           
             #include <streams.h>
           
             void error(char* p) {
                 cerr << p << "\n";
                     // cerr -     
                 exit(1);
             }
           
             void vector::set_size(int) { /*  */ }
           
             int& vec::operator[](int i) {
                 if (i<low || high<i) error("vec index out of range");
                                          //  vec  
                 return elem(i);
             }
           
             main() {
                 vector a(10); for (int i=0; i<a.size(); i++) {
                     a[i] = i; cout << a[i] << " ";
                 }
                 cout <<  "\n";  vec  b(10,19);  for  (i=0;  i<b.size();  i++)
                 b[i+10] = a[i]; for (i=0; i<b.size(); i++) cout << b[i+10] <<
                 " "; cout << "\n";
             }
           
              
           
             0 1 2 3 4 5 6 7 8 9
             0 1 2 3 4 5 6 7 8 9
           
                        
           .     , ,  -
                 , -
              ,        
              ,     ,  ..
                   .    
              ,   
           ,        
            .  ,      
                .      
              ,        
            .
           
                1.14   
           
                -   :
           
             class Vec : public vector { public:
                 Vec(int s)    :    (s)   {}   Vec(Vec&);   ~Vec()   {}   void
                 operator=(Vec&); void operator*=(Vec&); void operator*=(int);
                 //...
             };
           
                   
           ,  Vec::Vec(),        
             vector::vector()     .  -
            .   ,   -
            :
           
             void Vec::operator=(Vec& a) {
                 int s  = size();  if (s!=a.size()) error("bad vector size for
                 =");
                                      //     =
                 for (int i = 0; i<s; i++) elem(i) = a.elem(i);
             }
           
                  Vec    
           ,        vector  -
            ,     . , -
           ,    ,  vector    -
             :  (1)  vector   -
             (3)  vector      ,  
           .        Vec,  -
             Vec(Vec&):
           
             Vec::Vec(Vec& a) : (a.size()) {
                 int sz  =  a.size();  for  (int i = 0;  i<sz;  i++) elem(i) =
                 a.elem(i);
             }
           
                Vec    Vec,   -
                .
                   ,   =  +=,  
           ,        
             ,   ()  -
           .   ,        
            .    ,  +  -  -
             .   , ,   -
                    -
            .     ,  
                    +  
           operator+()  :
           
             Vec operator+(Vec& a,Vec &b) {
                 int s  = a.size();  if (s != b.size()) error("bad vector size
                 for +");
                                        //     +
                 Vec sum(s); for (int i=0; i<s; i++)
                     sum.elem(i) = a.elem(i) + b.elem(i); return sum;
             }
           
                ,      ,  
                  vector:
           
             #include <stream.h>
           
             void error(char* p) { cerr << p << "\n"; exit(1);
             }
           
             void vector::set_size(int) { /*...*/ }
           
             int& vec::operator[](int i) { /*...*/ }
           
             main() {
                 Vec a(10);  Vec b(10);  for (int i=0; i<a.size(); i++) a[i] =
                 i;  b = a;  Vec c = a+b;  for (i=0;  i<c.size(); i++) cout <<
                 c[i] << "\n";
             }
                1.15  (friend)
           
              operator+()      -
            .  ,     , 
             .        -
                 .  ,  
              "  " vector::elem(),  
              i         
            .     ,    -
           ,         
                  .     -
             ,        friend.
           ,  
           
             class Vec; // Vec -  
           
             class vector { friend Vec operator+(Vec, Vec); //...
             };
           
              
           
             Vec operator+(Vec a, Vec b) {
                 int s  = a.size();  if (s != b.size()) error("bad vector size
                 for +");
                                        //     +
                 Vec& sum = *new Vec(s);  int* sp = sum.v; int* ap = a.v; int*
                 bp = b.v; while (s--) *sp++ = *ap++ + *bp++; return sum;
             }
           
                   friend  ,
                    .   
           ,    vector  matrix,     
             (. #.8.8).
           
                1.16  
           
             "  ," -   ,  - "  ,  
                matrix,      ."
            ,  ++      
                 .     -
              ,    .   -
            ,    .
           
                 (#4.7),   -
            .  ,  vector -   ,
                 .     
           :
           
             #include <vector.h>
           
             declare(vector,int);
           
             main() {
                 vector(int) vv(10);  vv[2] = 3;  vv[10] = 4; // : 
                  
             }
              vector.h        ,   
           declare(vector,int)       
           vector,     ,    ,  
           implement(vector,int)            
           .    implement(vector,int)   -
               ,     
              ,     declare(vector,int) -
                  ,    
             .
           
             declare(vector,char);
             //...
             implement(vector,char);
           
                " ".    -
                  #7.3.5.
           
                1.17  
           
                  -     
                  :
           
             class common {
                 //...
             };
             class vector { common** v; //...
             public:
                 cvector(int); common*& elem(int);  common*&  operator[](int);
                 //...
             };
           
             ,       ,  
             ,     ""    -
           .       ,
           ,   ,  ,   ..  ,
                     
            ,       cvector
                         common
           . :
           
             class apple  :  public  common { /*...*/ } class orange :  public
             common { /*...*/ } class apple_vector : public cvector { public:
           
             cvector fruitbowl(100);
             //...
             apple aa;  orange oo;  //...  fruitbowl[0] = &aa;  fruitbowl[1] =
             &oo;  } ,    ,     
             ,
              .  ,     
           ,      common,     apple
             orange?        -
           ,      .   
              -        -
           ,  ,       -
             .       -
            .   ,  ,       
           apple:
           
             class apple_vector : public cvector { public:
                 apple*& elem(int i) { return (apple*&) cvector::elem(i); }
                 //...
             };
           
                (),  -
             common*& (    common),   
           cvector::elem,  apple*&.     -
                .     
           (        ,    
               ,  . #7.3.5), 
              ,         
                   .   
            ,  ,   vector(type),     
               (  implement()) 
             .   ,     
             ,        ,  
             -  -.
           
                1.18  
           
             ,          -
           .      shape,  -
             -  :
           
             class shape { point center; color col; //...
             public:
                 void move(point to) { center=to;  draw();  } point where()  {
                 return   center;   }   virtual   void  draw();  virtual  void
                 rotate(int); //...
             };
             ,         -
            (, move  where,  , ""  ""), -
              .       virtual,
               ,       .
           :
           
             class circle: public shape { int radius;
             public:
                 void draw(); void rotatte(int i) {} //...
             };
           
           ,  shape_vec -  ,   :
           
             for (int i = 0; i<no_of_shapes; i++) shape_vec[i].rotate(45);
           
                45  (  )
           
                     ,  
                  
           .     ,     -
              -     ?    ? 
           ,   !      .  -
                  .
                                         2   
           
                                  .
                                                             - .. 
           
                    (char,  int,  float  ..) 
                  (,  ,
             ..).       ,
               ,  ,  .  -
            ,  ,    ,   
             .      ++,  -
                .    -
              .    -
                    -
               ++.    ,  
           ,        
           4, 5  6    .
                2.1 
           
                  ()        ++
           ,     .  ,    
           ,    ,     
           .   ,   :
           
             char ch;  int count = 1;  char* name = "Bjarne"; struct complex {
             float  re,  im;  };  complex cvar;  extern complex sqrt(complex);
             extern   int   error_number;   typedef   complex   point;   float
             real(complex*   p)   {   return  p->re;  };  const  double  pi  =
             3.1415926535897932385; struct user;
           
                  ,      
                 .    -
                        
           ,     .   ch, count  cvar  -
                   ,     
              -    .  real
                 .      constant    pi        
           3.1415926535897932385.    complex     
           .   point   complex,  point  
           complex.  
           
             extern complex  sqrt(complex);  extern  int error_number;  struct
             user;
           
              .  ,  , 
             ,     - .  (-
           )  sqrt      ,  
             error_number  int    
           ,   -    user  ,
                  .   ++    
               ,      -
           ,         ,  -
             ,       :
           
             int count;  int count;  //  :    extern  int
             error_number;  extern int error_number; // : 
             
           
              -   (  extern . #4.2):
           
             extern int  error_number;  extern  int  error_number;   
               ""  ,  
           :
           
             struct complex { float re,  im;  };  typedef complex point; float
             real(complex*   p)   {   return   p->re  };  const  double  pi  =
             3.1415926535897932385;
           
              ,       ""  .    -
                   -
           :
           
             int count = 1;  char* name = "Bjarne";  //...  count = 2;  name =
             "Marian";
           
                
           
             char ch;
           
             .   ,   ,  
           .
           
                2.1.1  
           
                    .    ,    
                  .   ,
              (    ),   -
                     ,  
             .            
           (        )   
                 ,    
           .        () 
                .  ,   -
                   .   -
                   . :
           
             int x; //  x
           
             f() { int x; //  x   x x = 1; // -
                   x {
                     int x;  //    x x = 2;  // 
                       x
                 }
                 x = 3;     //    x
             }
           
             int* p = &x; //    x
           
                     .  
                ,   ,  -
            ,    ,   ,
             ,   .    -
            .         
            i  x   .
                    ::
               . :
           
             int x;
           
             f() {
                 int x = 1; //   x
                 ::x = 2;   //   x
             }
           
                   .
           
                   .   -
           ,            
           . :
           
             int x;
           
             f() {
                 int x = x; // 
             }
           
                ,    ,   
           ,    x "used before set" ("  ,  
           "),      . , ,  -
             ::,         -
              . :
           
             int x;
           
             f() //  {
                 int y = x; //  x int x = 22; y = x; //  x
             }
           
              y    x,  11,  -
                 x, 22.
                        
            , 
           
             f(int x) {
                 int x; // 
             }
           
            ,     x        -
            .
           
                2.1.2    (Lvalue)
           
                 ,      ,  
                   (-
           ,  *p[a+10]=7). ,     " 
           ".         
           ++:  "   . lvalue  , -
             " (#.5).   "lvalue"   
             ",        ".
              lvalue      -
           ;  lvalue,    (. #2.4).
           
                2.1.3  
           
                  ,      ,  
             ,   ,     
            ,       -
                 ()  ""   .
           ,      static,  -
             . *:
           
           
           *  #include <stream.h>      
              .     ,  
           ,    . (. )
             int a = 1;
           
             void f() {
                 int b = 1;  //     f()  static
                 int c = 1;  //     cout << " a =
                 " << a++
                      << " b = " << b++
                      << " c = " << c++ << "\n";
             }
           
             main() {
                 while (a < 4) f();
             }
           
            
           
             a = 1 b = 1 c = 1 a = 2 b = 1 c = 2 a = 3 b = 1 c = 3
           
                 (static)  
            .
           
                new  delete    
           ,          ,  .
           #3.2.4.
           
                2.2 
           
              ()         .
               .    _  -
           .  ++        ,  -
                    
           ( , ),  ,  ,   -
           .        -
               ,      .
             (,       $) 
            .        
             ++ (. #.2.3).  :
           
             hello this_is_a_most_unusially_long_name  DEFINED  foO bAr u_name
             HorseSense var0 var1 CLASS _class ___
           
               ,     -
             :
           
             012 a fool $sys class 3var pay.due foo~bar .name if
           
                    ,  
           Count  count -  ,    ,    -
               ,  . , -
             ,         
             ,         
            .
           
                     
           ,   ,   var10 -   ,    
           var,      10,  elseif -  ,   -
             else,      if.
                2.3 
           
               ()  ++    
              .    ,      
            (   ,    ),    -
            . :
           
             int error number; float real(complex* p);
           
              error_number     int,    ,
                ..     
           real     complex   . 
               .   ,   int   complex,
             .       
             .     
                 -  sizeof (   ,
                )  new (  
               ). :
           
             main() {
                 int* p = new int;  cout << "sizeof(int) =  "  <<  sizeof(int)
                 "\n";
             }
           
                     -
               , :
           
             float f;  char* p;  //...  long ll = long(p);  //  p 
             long int i = int(f); //  f  int
           
                2.3.1  
           
              ++    ,     
                   
             :
           
             char short int int long int
           
               ,
           
             float double
           
                ,
           
             unsigned char unsigned short int unsigned int unsigned long int
           
              ,   ,  
             ..        int
               ,     .  , long
            long int,   unsigned    unsigned int.  -
           ,     ,   int. :
           
             const a = 1; static x;
           
               int.
           
               char        
             ,    8- .   
           ++       char,      
           sizeof(char)==1.       char -
               .   unsigned char, ,
            ,        -
            ,  -     char 
               .
           
              ,       , 
                      , 
           ,       -
              .    
                  
              ,       -
            .     , ,  -
               .     -
               .   ,   -
               :
           
                1==sizeof(char)<=sizeof(short)<=     sizeof(int)<=sizeof(long)
                sizeof(float)<=sizeof(double)
           
                  ,    char  
               0..127 (     -
                ),   short  int    16
           ,   int  ,   ,  
           long       24 .   - 
            ,        -
           .       -
               #.2.6.
           
              (unsigned)       -
           ,       . -
            unsigned  int  ,           
             ,     -
            .   ,    -
           ,     unsigned,  -
            -   . :
           
             unsigned surprise = -1;
           
            (    ).
                2.3.2   
           
                     -
           .  ,   ,   ,  -
             .      #.6.6.
           
              ,        -
           .        ,
                ,   -
             .  ,  ,   
                      
              8- :
           
             int i1 = 256+255; char ch = i1 // ch == 255 int i2 = ch; // i2 ==
             ?
           
                ch=i1     ( !),   ch
               "-"  (..  8  );  
            i2       511!    
              i2?   DEC VAX,  char ,  
           -1,  AT&T 3B-20,  char ,   255.  ++ 
            (..    )  
                ,      
             ,     .
           
                2.3.3  
           
                    ( , -
            )   :
           
             * 
             & 
             []  () 
           
              . :
           
             int* a;  float v[10];  char* p[20]; //   20  
              void f(int); struct str { short length; char* p; };
           
                        -
             #.8.3-4.     ,   -
               . :
           
             int v[10];  //   i = v[3];  //   
             
           
             int* p;  //   i = *p; //  
                     -
              
           ,   *  & ,    [] () ,
                 ,   -
              ,      .  ,
              [] ,   *, 
           
             int* v[10];  //    int (*p)[10];  //  
             
           
                ,       
           .
           
                ,    ,   
           ,     .    
                 .       
               ,    .  ,
               :
           
             int x, y; // int x; int y;
           
                  ,   -
                (        
            ). :
           
             int* p, y; // int* p; int y;  int* y; int x, *p; // int x; int*
             p; int v[10], *p; // int v[10]; int* p;
           
               ,       
            ,    .
           
                2.3.4  void
           
              void ()      .  -
                       ,
             void  .     ,  
           ,      ,      
                .
           
             void f()  //  f    void* pv;  //  
               
           
                 void  (void  *),    
               .         
            ,   void*  ,   
                 void* .   ,  
               ,    
               ,      -
            .    , -
               .    -
                , ,   -
               . :
           
             void* allocate(int size);  //  void deallocate(void*); //
             
           
             f() {  int*  pi  =  (int*)allocate(10*sizeof(int));  char*  pc  =
                 (char*)allocate(10);
             //...
             deallocate(pi); deallocate(pc); }
                2.3.5 
           
                T T*      -
             T.  ,    T*    -
             T.         ,
            ,     :
           
             int* pi;  char**  cpp;  //         char int
             (*vp)[10];  //     10 int'  int  (*fp)(char,
             char*); //   
                                     //   (char, char*)
                                     //   int
           
                 - ,    
            ,    .    -
             .   -   *
           (). :
           
             char c1 = 'a';  char* p = &c1; //  p   c1 char c2 =
             *p; // c2 = 'a'
           
             ,    p,-  c1,   , 
             c1,   'a',    c2  *p 
           'a'.
           
                        
           .  ,  , ,    
            (   0):
           
             int strlen(char* p) {
                 int i = 0; while (*p++) i++; return i;
             }
           
                   ,     -
            ,          :
           
             int strlen(char* p) {
                 char* q = p; while (*q++) ; return q-p-1;
             }
           
                   .   -
             #4.6.7.
                2.3.6 
           
               T T[size]   "  size   
           T".   ()  0  size-1. :
           
             float v[3];  //        float:  v[0],  v[1],  v[2] int
             a[2][5];  //     int char* vpc;  //    32
               
           
                        
             :
           
             extern int strlen(char*);
           
             char alpha[] = "abcdefghijklmnoprstuvwxyz";
           
             main() {
                 int sz = strlen(alpha);
           
                 for (int i=0; i<sz; i++) { char ch = alpha[i]; cout << "'" <<
                     chr(ch) << "'"
                          << " = " << ch
                          << " = 0" << oct(ch)
                          << " = 0x" << hex(ch) << "\n";
                 }
             }
           
              chr()        
           ;  ,  chr(80)  "P"  ,   -
                 ASCII.    oct()    
              ,   hex()  -
                ;  chr() oct()  hex()
             <stream.h>.   strlen()   
              alpha;      -
             alpha (#2.4.4).      ASCII,
              :
           
             'a' = 97 = 0141 = 0x61
             'b' = 98 = 0142 = 0x62
             'c' = 99 = 0143 = 0x63
             ...
           
             ,     alpha .  -
                  ,    -
            .      
             - ,       -
            .      -
           . :
           
             char v[9]; v = ""; // 
           
           ,      . -
             ,      
            .          
           .           .
           :
           
             int v1[] = { 1, 2, 3, 4 }; int v2[] = { 'a', 'b', 'c', 'd' };
           
             char v3[] = { 1, 2, 3, 4 }; char v4[] = { 'a', 'b', 'c', 'd' };
           
             ,  v4 -    (  ) ;   
            ,           
           .       -
            .
           
                  ,  -
                 ,       
           ,     ,     (,)  
             (.  #3.2.2).  ,  , 
           :
           
             int bad[5,2]; // 
           
            :
           
             int v[5][2];  int bad = v[4,1];  //  int good = v[4][1]; //
             
           
             
           
             char v[2][5];
           
               ,     -
             char[5].           
                ,    -  
           .
           
             char v[2][5] = {
                 'a', 'b', 'c', 'd', 'e',
                 '0', '1', '2', '3', '4'
             }
           
             main() { for (int i = 0; i<2; i++) {
                     for (int j = 0; j<5; j++) cout << "v[" << i << "][" << j
                              << "]=" << chr(v[i][j]) << " ";
                     cout << "\n";
                 }
             }
           
              
           
             v[0][0]=a v[0][1]=b  v[0][2]=c  v[0][3]=d   v[0][4]=e   v[1][0]=0
             v[1][1]=1 v[1][2]=2 v[1][3]=3 v[1][4]=4
                2.3.7   
           
                 ++   .    
                 ,    
               :
           
             char alpha[] = "abcdefghijklmnopqrstuvwxyz";  char*  p  =  alpha;
             char ch;
           
             while (ch = *p++) cout << chr(ch) << " = " << ch
                      << " = 0" << oct(ch) << "\n";
           
              p     
           
             char* p = &alpha[0];
           
                   ,   -
                    
            . ,  
           
             extern int strlen(char*);  char v[] = "Annemarie";  char* p =  v;
             strlen(p); strlen(v);
           
            strlen            .
              ,     ;    -
                ,    v   
            (#4.6.3).       -
             +, -, ++  --    ,  
            .     p  T*    -
            , ,  p    
             T; p+1     ,  p-
           1 -  .   ,    p+1  
           sizeof(T)   p. , 
           
             main() {
                 char cv[10]; int iv[10];
           
                 char* pc = cv; int* pi = iv;
           
                 cout <<  "char*  "  <<  long(pc+1)-long(pc) << "\n";  cout <<
                 "int* " << long(ic+1)-long(ic) << "\n";
             }
           
           
           
             char* 1 int* 4
           
                   ,  
              .      
               long     
           (#3.2.5).     long,     ""  int,
               ,         int (
           , sizeof(int)<sizeof(long) ).
                 ,   
                   (      
            ,   ).     -
            ,      
             ( ).      
               ;      
             .        
             ,     ,  -
               . :
           
             int v1[10]; int v2[10];
           
             int i = &v1[5]-&v1[3]; // 2 i = &v1[5]-&v2[3]; //  -
                 
           
             int* p = v2+2; // p == &v2[2] p = v2-2; // p 
           
                2.3.8 
           
                  ,  struct  
             ()  . :
           
             struct address { //   char* name; //  "Jim Dandy"
                 long number;  //   61 char* street;  //  "South
                 Street" char* town; //  "New Providence" char* state[2];
                 //  'N' 'J' int zip; //  7974
             }
           
             ,  address ( ), 
            ,    ,    -  -
             (  ,  address    
               ,        -
           ).           ;    
               ++,        
             ,      .
           
               address    ,  
           ,         -
            . (). :
           
             address jd;  jd.name = "Jim Dandy"; jd.number = 61; , -
                 , 
                . :
           
             address jd = { "Jim Dandy", 61, "South Street", "New Providence",
                 {'N','J'}, 7974
             };
           
                  (#5.2.4).  ,
                jd.state   "NJ".  
             '\0',    "NJ"  ,   
            ,    jd.state.
           
                      
             ->. :
           
             void print_addr(address* p) {
                 cout << p->name << "\n"
                     << p->number << " " << p->street << "\n"
                     << p->town << "\n"
                     << chr(p->state[0]) << chr(p->state[1])
                     << " " << p->zip << "\n";
             }
           
                 ,   -
                   . :
           
             address current;
           
             address set_current(address next) {
                 address prev = current; current = next; return prev;
             }
           
               ,     (==  !=) 
           .       , .
            6.         
              .     ,   -
            ,       
                      (
           :        ),   
                 ,    -
             .    ""  . , (
            ) sizeof(address)  24,   22,    -
           .
             ,        , 
            ,      ,   
            . :
           
             struct link{ link* previous; link* successor;
             }
           
                     ,  
              , 
           
             struct no_good { no_good member;
             };
           
             (     no_good).
               ( )   
             ,         .
           :
           
             struct list; //    
           
             struct link { link* pre; link* suc; link* member_of;
             };
           
             struct list { link* head;
             }
           
                  list   link    -
            .
           
                2.3.9  
           
                      -
               . :
           
             struct s1 { int a; }; struct s2 { int a; };
           
              , 
           
             s1 x; s2 y = x; // :  
           
                   , 
           
             s1 x; int i = x; // :  
           
             ,           
              .    typedef  
              ,     . :
           
             typedef char* Pchar; Pchar p1, p2; char* p3 = p1;
           
                  .
                2.3.10 
           
                 .    
                ,  -
           ;      6.       -
             .   x&    x.  -
           :
           
             int i = 1;  int& r = i; // r  i     int int
             x = r // x = 1 r = 2; // i = 2;
           
                 (  -,  
             ). ,     
               .
           
              ,        . -
           :
           
             int ii = 0; int& rr = ii; rr++; // ii   1
           
           ,  rr++   ;    ++ -
             int,    ii. ,  -
                 ;    
            ,       ()  -
           .      ,  -
            rr,   &rr.
           
                    -
           ,     .  
               ,      
           lvalue (,     , . #.5). 
              &T     lvalue,    
              T.   :
           
             [1] -,   ,    
                (#.6.6-8, #.8.5.6),
           
             [2]        
                
           
             [3] ,        -
                .
           
            
           
             double& dr = 1;
           
             :
           
             double* drp; // ,    double temp;
             temp = double(1); drp = &temp;
           
             int x = 1; void incr(int& aa) { aa++; } incr(x) // x = 2  -
                  ,  
           ,   aa  incr    
              x.  ,     ,   -
                ,   -
             .      -
                   :
           
             int x = 1; int next(int p) { return p+1; } x = next(x); // x = 2
           
             void inc(int* p) { (*p)++; } inc(&x); // x = 3
           
                   ,  -
               ,     . ,
                      
               ,   .  
                .   
               :
           
             struct pair { char* name; int val;
             };
           
                 ,       
             .     find(), 
             ,     pair  
                ,     .
                 (  -
           ) :
           
             const large = 1024; static pair vec[large+1};
           
             pair* find(char* p)
             /*
                    "pair":
                  p,  ,   "pair",  
                  "pair"
             */
             { for (int i=0; vec[i].name; i++)
                     if (strcmp(p,vec[i].name)==0) return &vec[i];
           
                 if (i == large) return &vec[large-1];
           
                 return &vec[i];
             }
                      value(),   
            ,    ( 
           ):
           
             int& value(char* p) {
                 pair* res  = find(p);  if (res->name == 0) { //    
                 :
                   res->name =   new  char[strlen(p)+1];  //  
                   strcpy(res->name,p); res->val = 0; //   0
                 }
                 return res->val;
             }
           
                   value()   -
            (    );    -
              .   , , :
           
             const MAX = 256; //    
           
             main()
             //       
             { char buf[MAX];
           
                 while (cin>>buf) value(buf)++;
           
                 for (int i=0;  vec[i].name;  i++) cout << vec[i].name << ": "
                     << vec [i].val << "\n";
             }
           
                      
            cin  buf (.   8),        
              find(). , ,   
               ,       -
           . ,  
           
             aa bb bb aa aa bb aa aa
           
             :
           
             aa: 5 bb: 3
           
                     -
                     (#6.7)
            [].
                2.3.11 
           
                       ()
             ,     .  
                        
             ,   ,   -
            .        ,  
                .   
                register. :
           
             register int i; register point cursor; register char* p;
           
              register      , -
                .    
            register          
             (      -
                 ).
           
                ,   register, 
               .
           
                2.4 
           
             ++       :  
           ,       .  ,
             (0)        
           ,        char[].  
               .    -
            ,          -
           .   ++     : (1) 
                     -
           ,        const; (2)  -
                 ;    (3)  
                .
           
                2.4.1  
           
                  : , -
           ,      .  -
                   ,     
           :
           
             0 1234 976 12345678901234567890
           
                 int,   ,   
            int,      long.   -
             ,       -
           .
             ,       x (0x), -
              (  16),  , -
                 ,    
            (  8).    :
           
             0 02 077 0123
           
              -  0,  2,  63, 83.  
               :
           
             0x0 0x2 0x3f 0x53
           
              a,  b,  c, d, e  f,      ,
               10, 11, 12, 13, 14  15, -
           .      -
                       
                . ,  ,
             int     -
            , 0xffff     -1; 
                  ,  
               65535.
           
                2.4.2    
           
                   double.    
           ,          
           ,    ,       .
                :
           
             1.23 .23 0.23 1. 1.0 1.2e10 1.23e-15
           
           ,              
            .  ,  65.43 e-21    
             ,         
           ():
           
             65.43 e - 21
           
              .
           
                     ; 
           float,      (#2.4.6):
           
             const float pi = 3.14159265;
                2.4.3  
           
               ++      , , -
                ,      -
              .    -  , -
              ; , 'a'  '0'.  
                   
                   ,  -
               (    
            ,    ,   -
           ).  ,     , 
             ASCII,   '0'  48,    -
             EBCDIC  ,    240. 
                  
           .        ,  
              \   escape-:
           
                 '\b',  
                 '\f',  
                 '\n',  
                 '\r',  
                 '\t',  
                 '\v',  
                 '\\', \   ( )
                 '\'',   '
                 '\"',   "
                 '\0', null,  ,   0
           
                      .  
              -,  -   
            ( \,      ),   -,
           -     (\x,    
            ). :
           
             '\6' '\x6' 6 ASCII ack
             '\60' '\x30' 48 ASCII '0'
             '\137' '\x05f' 95 ASCII '_'
           
                     -
           ,            
           (.  ).      -
                    
           .
                2.4.4 
           
               -   ,  -
               "
           
             " "
           
                      ,  
           ;      '\0'   0.
           :
           
             sizeof("asdf")==5;
           
                "    ", -
             "asdf"    char[5].     "" (
               char[1]).   ,               s
           strlen(s)==sizeof(s)-1,  strlen()   
           0.
           
                        
                   .    -
                escape-.    
              , ,    '\n'.
           :
           
             cout << "   \007\n"
           
            7 -  ASKII  bel ().
           
                 ""  :
           
               "  ,   "
           
                   ,    
             ;  ,    . :
           
               cout << "  \ ok"
           
           
           
                 ok
           
              ,    escape ( ),  -
                 ,    
            .
           
                    ,     
            ,      .  , 
           "asdf\000hjkl"    ,  
           strcpy()  strlen(),  "asdf".
           
                      
                  
            .            
              ,        
           .   :
           
               char v1[] = "a\x0fah\0129";  // 'a' '\xfa' 'h' '\12'  '9'  char
               v2[]  =  "a\xfah\129";  // 'a' '\xfa' 'h' '\12' '9' char v3[] =
               "a\xfad\127"; // 'a' '\xfad' '\127'
           
               ,       -
             9-   .
                2.4.5 
           
                     ,  
             .        0.
              .   (    )  
              -  .
           
                2.4.6 Const
           
               const     ,  
              ,   . :
           
             const int model = 145; const int v[] = { 1, 2, 3, 4 };
           
                 ,    -
           .   -  const ,  
                :
           
             model = 145; //  model++; // 
           
             ,  const  ,        
            ,   ,    -
            .    ,    ,
               const:
           
             const char* peek(int i) {
                 return private[i];
             }
           
                     ,  -
            -  ,        
            ( -).
           
               ,      -
            ,      (,  
            ,   ).   -  , 
                 ,    
             .  ,    ( 
           )   ,       -
                 .      
             ,       
            ,        -
           .          
                     -
           ,    .
           
                 :      
            .     "" const
            ,    , . :
           
             const char* pc = "asdf";  //    pc[3] =  'a';
             //  pc = "ghjk"; // ok    const , 
               , 
           ,   const*. :
           
             char *const cp = "asdf"; //   cp[3] = 'a'; //
             ok cp = "ghjk"; // 
           
                   ,        
           const. :
           
             const char  *const  cpc  =  "asdf";  //  const   const
             cpc[3] = 'a'; //  cpc = "ghjk"; // 
           
             ,          -
           ,    ,    
           .       . 
               const   
           ,    . :
           
             char* strcpy(char* p, const char* q); //    q
           
                          ,
                      .   
              ,        
           ,        .
           :
           
             int a = 1;  const c = 2; const* p1 = &c; // ok const* p2 = &a; //
             ok int* p3 = &c; //  *p3 = 7; //   c
           
              ,     ,    int.
                2.4.7 
           
                  ,    -
            ,   const. :
           
             enum { ASM, AUTO, BREAK };
           
               ,   -
           ,     .   -
                   0   ,
             :
           
             const ASM = 0; const AUTO = 1; const BREAK = 2;
           
              . :
           
             enum keyword { ASM, AUTO, BREAK };
           
                  int,        .
             keyword,     int,    -
           ,         ,    
           . :
           
             keyword key;
           
             switch (key) { case ASM:
                 // - 
                 break; case BREAK:
                 // - 
                 break;
             }
           
              ,      
            keyword   .
           
                  . :
           
             enum int16  { sign=0100000,  //  most_significant=040000,  //
                   least_significant=1 //  
             };
           
                   ,  -
             .
                2.5  
           
                   -
            ,         ,  
             .      
            ,  :
           
             [1]        
           
             [2]         -
                    .
           
                     ,   -
             .     -
             .         
            ,         ,
               ,     .
                 ;  ,  
                   (#3.2.6)   
              .
           
                2.5.1 
           
              char    ,  -
           ,   /,    -
           ,   char   ,   ++ 
            . , ,   
                 struct.   
                   ,   -
           .   ;      -
             ,      -   
           :
           
             struct sreg { unsigned enable :  1; unsigned page : 3; unsigned :
                 1;  //  unsigned mode : 2; unsigned : 4: // -
                  unsigned  access  :  1;  unsigned  length  :  1;
                 unsigned non_resident : 1;
             }
           
                0  DEC PDP11/45 (  -
           ,       ).  
                    :  
              .     
               ,   ,  -
                .        
            sreg     :
           
             sreg* sr0 = (sreg*)0777572;
             //...
             if (sr->access) { //  
                 //  
                 sr->access = 0;
             }
                     
                   .    -
           ,   ,   ,   -
             ,    . -
            ,    ,    -
                 !  , 
            char  int   ,     .    -
                     -
                     -
             .
           
                2.5.2 
           
                  ,    
               ,        -
           ,  :
           
             struct entry  {  char* name;  char type;  char* string_value;  //
                   type == 's' int int_value;  // 
                  type == 'i'
             };
           
             void print_entry(entry* p) {
                 switch p->type { case 's':
                     cout << p->string_value; break;
                 case 'i':
                     cout << p->int_value; break;
                 default:
                     cerr << " type\n"; break;
                 }
             }
           
              string_value  int_value        -
            ,  ,    . 
             ,  ,          
           union. , :
           
             struct entry { char* name; char type; union {
                     char* string_value;  //   type == 's' int
                     int_value; //   type == 'i'
                 };
             };
           
                 ,   entry,  -
           ,   ,     entry  string_value  
           int_value      .   ,   
                ,    
            .
                ,     -
               ,      -
           ,  .      -
           ,       ,  
           -       
           .    @    ,  
                     
            (#5.4.6).
           
                   "  
           " (    ,   -
           ,     ,  -
             ).  ,  ""  VAX' int
            int*,    :
           
             struct fudge { union {
                     int i; int* p;
                 };
             };
           
             fudge a; a.i = 4096; int* p = a.p; //  
           
                    :   -
            int  int*    ,   
                 .    -
             ,       
            (#3.2.5).
           
                ,    -
            .  ,  ,   fudge,  
             0:
           
             fudge.p = 0; int i = fudge.i; // i     0
           
                 ,      -
            . , fudge     :
           
             union fudge { int i; int* p;
             };
           
             ()    .   
              , . #5.4.6.
                2.6 
           
             1. (*1)     "Hello, world" (1.1.1).
           
             2. (*1)       #2.1    :  
                   ,    -
                .     ,     
                ,      .
           
             3. (*1)   :   ;  
                10 ;     10 ;    
                 ;      ; -
                 ;     ;    
                  .    .
           
             4. (*1.5)  ,     
                 .   sizeof.
           
             5. (*1.5)  ,     'a'...'z' 
                  '0'...'9'      .     
                  .    ,    
                 .
           
             6. (*1)   ,   
                0   . : #2.5.2.
           
             7. (*1.5)  ,       -
                  double.
           
             8. (*2)     ,    -
                ,   :  char,  short, int, long, float, double,
                unsigned, char*, int*  void*?    -
                    ?   , , int*
                  ?     -
                  ?  , , int   ?
           
             9. (*1)           
                ++    ?     
                   ++     ?    
                -   ,   
                 ?
           
             10. (*2)  one  :
           
                  const one = 1;
           
                   one  2.  num -
                 :
           
                  const num[] = { 1, 2 };
           
                   num[1]  2.
             11. (*1)  ,        (
                ).      int*. -
                   ,    
                 int&.
           
             12. (*1)    str   :
           
                  char str[] = "a short string";
           
                   "a short string"?
           
             13. (*1.5)         
                 .   .    :   
                             ,    
                  ,      -
                      .
           
             14. (*1)      typedef  :   char,
                  char,   ,  
                  char,     ,   7
                 ,     7  , 
                  8   7  .
                               3   
           
                                                               ,
                                           
                                                                -  
           
             ++  ,        
                    
             .        
              .    -
                    -
                 .    
            ,       *   -
           .
             *    ,  
           indentation.    . (. .)
                3.1  
           
                         
              ,    -
                      .
               . ,  -
           
           
             r=2.5 area=pi*r*r
           
           (pi  ),    :
           
             2.5
             19.635
           
            2.5  -    ,   19.635 - 
           .
           
                   :    -
             (parser'),   ,    -
             ().  ,   -
           ,        -
            ,        
           ,       ,  -
             ,    . -
                    ,    
            ,           -
               (200 ),      -
                   -
             ++.
                3.1.1   
           
               ,  :
           
             program:
                 END // END -    expr_list END
           
             expr_list:
                 expression PRINT // PRINT -   '\n'   ';'  expression
                 PRINT expr_list
           
             expression:
                 expression + term expression - term term
           
             term:
                 term / primary term * primary primary
           
             primary:
                 NUMBER //      ++ NAME //   ++  
                  '_' NAME = expression - primary ( expression )
           
              ,     . 
                 ,   .
               ,     *,
           /,  +,  - (  )  =.        
             .
           
                     -
               .    ,  ++,  -
                 ,       
           .        ,
               .    (,  END,
           NUMBER, +  -)    get_token(), 
                 -
            expr(),  term()  prim().     ()-
            ,  ;      
             .
                            
           get_token().    get_token()   -
             curr_tok;  curr_tok       
           token_value:
           
             enum token_value { NAME NUMBER  END  PLUS='+'  MINUS='-'  MUL='*'
                 DIV='/' PRINT=';' ASSIGN='=' LP='(' RP=')'
             };
             token_value curr_tok;
           
                    ,     
           get_token(),    curr_tok    ,  
           .        -
             ()       
               ,   ,  -
               .      
           ""    .  expr() 
             ;      ,   
               :
           
             double expr() //    {
                 double left = term();
           
                 for(;;) // ```` switch(curr_tok) { case PLUS:
                         get_token(); //  '+' left += term(); break;
                     case MINUS:
                         get_token(); //  '-' left -= term(); break;
                     default:
                         return left;
                     }
             }
           
                   .   ,  -
                    -
           ,        .  ,
             2-3+4   (2-3)+4,    -
           .
           
               for(;;) -     -
            .      ""*.    
             for,   - while(1).  
           switch    ,       +  -,  
              return   default.
           
           
           *  : "for" - "forever" (). (. .)
              +=, -=      -
           .                
           left=left+term()      left=left-term().      left+=term()  
           left-=term()   ,        -
            .     @  x@=y 
           x=x@y   ,   x    .  
              
           
             + - * / % & | ^ << >>
           
               :
           
             += -= *= /= %= &= |= ^= <<= >>=
           
                 ,   a+ =1  -
             -   +  =. (%  -
              ;  &,|  ^    , 
             ;  <<  >>        
           ).    term()    get_token()       
           expr().
           
                    ,    
             4.             
               ,    -
                       .   
           expr(),     term(),     prim(),
                  expr().     -
           ; 
           
             double expr(); //   
           
            prim()    .  term() -
                 
           :
           
             double term() //    {
                 double left = prim();
           
                 for(;;) switch(curr_tok) { case MUL:
                         get_token(); //  '*' left *= prim(); break;
                     case DIV:
                         get_token(); //  '/' double d = prim();  if (d  ==
                         0) return error("  0"); left /= d; break;
                     default:
                         return left;
                     }
             }
           
             ,  ,     ,   
             ,  ,       
                  .   error(char*)
             .  d    ,  
           ,    .     
               .      -
                     /
            .       -
                 ;   -
            ,     ,  -
                 ,    
             *.  ,   = 
            ,  ==  .
           
           
           *           
           . (.  )  prim,   primary,
                 
            ,   ,       -
           ,      ,       
              :
           
             double prim() //  primary () {
                 switch (curr_tok) { case NUMBER:  //      
                 
                     get_token(); return number_value;
                 case NAME:
                     if (get_token()    ==    ASSIGN)    {    name*    n     =
                         insert(name_string);  get_token(); n->value = expr();
                         return n->value;
                     }
                     return look(name-string)->value;  case MINUS:  // 
                 
                     get_token(); return -prim();
                 case LP:
                     get_token(); double e  =  expr();  if  (curr_tok  !=  RP)
                     return error("  )"); get_token(); return e;
                 case END:
                     return 1; default:
                     return error("  primary");
                 }
             }
           
               NUMBER ( ,      ),
             .    get_token()  -
               number_value.     -
                 ,   
            ,          .
                   .    
               :  ,   
           (      token_value),    ( ) 
           .        curr_tok, -
                  NUMBER -
                number_value.    
             ,        
                 .
              ,        NUMBER  
           number_value,   name_string          
              NAME.  ,  -
               ,        ,  
           ,        ,    
           .         . 
                 #3.1.3;     ,   
              :
           
             srtuct name { char* string; char* next; double value;
             }
           
            next   ,   
            :
           
             name* look(char*); name* insert(char*);
           
                  name,      -
            ;  look()  ,     
           .   ,       
              ,       -
               .
                3.1.2  
           
               -     .   
           ,        ,   
              ,     -
           .         -
                ( )   -
           .       ,  -
                      -
             .         
               .        
           get_token().   ,     
               ;      
             .
           
                    ,  
                      -
           ;            
           get_token()  .
           
                 ,      '\n' -
              ,       
              .   ,    '\n' -
               .      ,  
             (,    ..):
           
             char ch
           
             do {  //     '\n' if(!cin.get(ch))
                 return curr_tok = END;
             } while (ch!='\n' && isspace(ch));
           
              cin.get(ch)         
             ch.  if(!cin.get(ch))    ,  
           cin       .     
           END,     .  -
             !  (),   get()     
           .
           
              (inline) isspace()  <ctype.h>   
             ,      (#8.4.1);  isspace(c)
             ,  c   , 
              .        -
           ,   isspace()  ,  
                 ;          
           isalpha(),  isdigit()      isalnum(),         
           get_token().
              ,     ,   -
              ,      -
           .       ,  
              .   '\n'  ';' -
            :
           
             switch (ch) { case ';': case '\n':
                 cin >> WS; //   return curr_tok=PRINT;
           
                 ,    -
               get_token().  WS -    -
            ,   <stream.h>;    
            .         -
                get_token().     ,
                case ()     
              ,    . 
               PRINT    curr_tok.
           
               :
           
             case '0': case '1': case '2': case '3': case '4':
             case '5': case '6': case '7': case '8': case '9':
             case '.':
                 cin.putback(ch); cin >> number_value; return curr_tok=NUMBER;
           
                 case ,    ,
              ,       ,  
                  .
           
                >>         
              double,        
           :    (  )  
            cin,       number_value.
           
             ,    NAME,     ,    
                :
           
             if (isalpha(ch))  {  char*  p  =  name_string;  *p++ = ch;  while
                 (cin.get(ch) && isalnum(ch)) *p++ = ch; cin.putback(ch); *p =
                 0; return curr_tok=NAME;
             }
                    name_string ,   .
            isalpha()  isalnum()     <ctype.h>;  isalnum(c)  
           ,  c   ,    .
           
             , ,   :
           
             token_value get_token() {
                 char ch;
           
                 do {   //                 '\n'
                     if(!cin.get(ch)) return curr_tok = END;
                 } while (ch!='\n' && isspace(ch));
           
                 switch (ch) { case ';': case '\n':
                     cin >> WS; //   return curr_tok=PRINT;
                 case '*':
                 case '/':
                 case '+':
                 case '-':
                 case '(':
                 case ')':
                 case '=':
                     return curr_tok=ch;  case '0':  case '1':  case '2': case
                 '3':  case '4':  case '5': case '6': case '7': case '8': case
                 '9': case '.':
                     cin.putback(ch); cin     >>     number_value;      return
                     curr_tok=NUMBER;
                 default: // NAME, NAME=   if (isalpha(ch)) {
                         char* p = name_string;
                         *p++ = ch;
                         while (cin.get(ch)   &&   isalnum(ch))   *p++  =  ch;
                         cin.putback(ch); *p = 0; return curr_tok=NAME;
                     }
                     error(" "); return curr_tok=PRINT;
                 }
             }
           
              token_value ( )   
                *,     -
           .
           
           
           *   . (. .)
                3.1.3  
           
                     
           
             name* look(char* p, int ins =0);
           
                ,       
             .   =0  ,  -
              ,   look()     
           .     ,  look("sqrt2") 
           look("sqrt2",0),    ,     . 
                   ,  -
             :
           
             inline name* insert(char* s) { return look(s,1);}
           
                ,     :
           
             srtuct name { char* string; char* next; double value;
             }
           
              next         -
           .
           
               -        name:
           
             const TBLSZ = 23; name* table[TBLSZ];
           
                     ,  
                 table    
           .
                      look()  
             (      -  
           ):
           
             int ii = 0; //  char* pp = p; while (*pp) ii = ii<<1 ^
             *pp++; if (ii < 0) ii = -ii; ii %= TBLSZ;
           
              ,             
            ""  ii (""  ).    x^y
                ,  -
              x  y .     
           , ii     ,     
             .      :
           
             ii <<= 1; ii ^= *pp++;
           
             ,  ^   ,   +.    -
             -   . 
           
             if (ii < 0) ii = -ii; ii %= TBLSZ;
           
           ,  ii     0...TBLSZ-1;  % - 
               (   ).
               :
           
             extern int strlen(const char*);  extern int  strcmp(const  char*,
             const char*); extern int strcpy(const char*, const char*);
           
             name* look(char* p, int ins =0) {
                 int ii = 0;  //  char* pp = p;  while (*pp)  ii  =
                 ii<<1 ^ *pp++; if (ii < 0) ii = -ii; ii %= TBLSZ;
           
                 for (name*   n=table[ii];   n;   n=n->next)   //      if
                     (strcmp(p,n->string) == 0) return n;
           
                 if (ins == 0) error("  ");
           
                 name* nn  =  new  name;   //      nn->string   =   new
                 char[strlen(p)+1];   strcpy(nn->string,p);   nn->value  =  1;
                 nn->next = table[ii]; table[ii] = nn; return nn;
             }
           
               - ii     -
             next.   name    -
               strcmp().     ,   
           name,    name.
           
               name        
                new (. #3.2.6),  -
           ,        .    
                  ,   
               ,   ,  . 
                    .  
           strlen()    ,     ,
           new -    ,  strcpy() -   -
             .
                3.1.4  
           
                  ,     
            .      , -
                  :
           
             int no_of_errors;
           
             double error(char*  s)  {  cerr  <<  "error:  "  <<  s  <<  "\n";
                 no_of_errors++; return 1;
             }
           
               ,      -
             ,       -
             ,    ,     -
                .    -
              .   get_token()  -
            ,   error()    ,  -
             .      ,  
             .
           
               ,       -
           ,       .
                 exit(),    -
               (#8.3.2),      
                 .  -
               -   abort(),   -
                   - -
              ( );    ,  -
           ,   .
           
                3.1.5 
           
                  ,      
              ,     .   
            main()   :
           
             int main() {
                 //   :
                 insert("pi")->value =                  3.1415926535897932385;
                 insert("e")->value = 2.7182818284590452354;
           
                 while (cin)  {  get_token();  if (curr_tok == END) break;  if
                     (curr_tok == PRINT) continue; cout << expr() << "\n";
                 }
                 return no_of_errors;
             }
           
              ,   main()     -
                  ,   
                 .     -
           ,        
              .
                -     .   -
            :
           
             cout << expr() << "\n";
           
              cin           
             ,      -  ,  
             END      ,   get_token()
             .  break    -
               switch    ( ,
            for,  while   do).   PRINT
           ( ,   '\n'  ';')  expr()   -
             .   continue   
             ,    
           
             while (cin) {
                 // ...
                 if (curr_tok == PRINT) continue; cout << expr() << "\n";
             }
           
           
           
             while (cin) {
                 // ...
                 if (curr_tok == PRINT) goto end_of_loop;  cout <<  expr()  <<
                 "\n"; end_of_loop
             }
           
                  #.9.
           
                3.1.6   
           
              ,       ,  -
           ,          
           ,         -
             .        -
               ,      
             .
           
               ,     main().  
            , main()      -
           ,    argc   ,  -
            argv.   -   ,  argv 
             char*[argc].      (,      
           )    argv[0],  argc   -
            . ,   
           
             dc 150/1.1934
           
             :
           
             argc 2  argv[0]  "dc" argv[1] "150/1.1934"  
               
           .     ,      -
           .           ,
                    ,    
            (#8.5).  ,    cin      
            :
           
             int main(int argc, char* argv[]) {
                 switch(argc) { case 1: //    
                     break; case 2: //   
                     cin = *new istream(strlen(argv[1]),argv[1]); break;
                 default:
                     error("  "); return 1;
                 }
                 //  
             }
           
                  ,      
           main()             
           switch.        main() ,   
               ,    
           ,  ,     
             :
           
             dc "rate=1.1934;150/rate;19.75/rate;217/rate"
           
               ,   ;    -
              UNIX.
           
                3.2   
           
              ++      #.7; -
           ,  ,  .     -
               .     -
                     -
           .    _ -   ,  -  -
           ,   - ,      , -
            - ,    ,  - , 
           lvalue - ,    .    
                   ( * ()  ..) 
               ,       -
           .
           
                   ,  
            .  ,  a=b=c  a=(b=c),
           a+b+c  (a+b)+c,  *p++  *(p++),   (*p)++.
                          ( 1)
           Ŀ
             ::    _ ::            
             ::  ::                                          
           Ĵ
             ->   ->                               
             []   [  ]                              
             ()    (_)                            
             ()    (_)                      
             sizeof   sizeof                              
             sizeof   sizeof (  )                            
           Ĵ
             ++   lvalue++                                 
             ++   ++lvalue                                    
             --   lvalue--                                 
             --   --lvalue                                    
             ~  ~                                            
             !  !                                                    
             -   -                                         
             +   +                                          
             &   & lvalue                                     
             *  *                                         
             new  () new                             
             delete  () delete            
             delete[]   delete[  ]          
             ()  ( ) (  )               
           Ĵ
             *   *                                         
             /   /                                           
             %    ()  %                        
           Ĵ
             +  ()  +                                   
             -  ()  -                                 
           
           
                     -
           .     ,       ,
             .  :  a+b*c  a+(b*c),    *
             ,   +,  a+b-c  (a+b)-c,  +
            -    (  + ).
                         ( 2)
           Ŀ
             <<   lvalue <<                                  
             >>   lvalue >>                                 
           Ĵ
             <   <                                            
             <=     <=                                
             >   >                                            
             >=     >=                                
           Ĵ
             ==   ==                                           
             !=    !=                                        
           Ĵ
             &    &                                       
           Ĵ
             ^     ^                         
           Ĵ
             |     |                          
           Ĵ
             &&    &&                                    
           Ĵ
             ||     ||                       
           Ĵ
             ? :  if  ?  :                         
           Ĵ
             =   lvalue =                           
             *=    lvalue =                          
             /=    lvalue /=                        
             %=      lvalue %=                  
             +=    lvalue +=                          
             -=    lvalue -=                          
             <<=     lvalue <<=                 
             >>=     lvalue >>=                
             &=    lvalue &=                                
             |=     lvalue |=                   
             ^=     lvalue ^=                  
           Ĵ
             ,  ()  ,                              
           
                3.2.1  
           
                ++  ;     
              :    -
                  ,      
             (  ),     -
             ,        .  
           ,      ,     
                 , -
             "  " ( ,  -
              ). , 
           
             if (i<=0 || max<i) // ...
           
           .   ,  ,     -
             ,     ,    
                  
           
             if ( (i<=0) || (max<i) ) // ...
           
                    
            ,       -
           ,        ,  
                .  
            ,        ""
           .  
           
             if (i&mask == 0) // ...
           
               mask  i     -
             .  ==   ,  &, -
              i&(mask==0).     -
            :
           
             if ((i&mask) == 0) // ...
           
             ,     ,  ,      
           ,     ,   :
           
             if (0 <= a <= 99) // ...
           
            ,      (0<=a)<=99,  -
                  0  1,    a (  a 
            1).  ,   a   0...99,  -
           
           
             if (0<=a && a<=99) // ...
                3.2.2  
           
                  . 
           
             int i = 1; v[i] = i++;
           
               v[1]=1,    v[2]=1.    
                    
             .   ,    -
                 ,    
             .
           
               &&  || ,    
            ,  . , b=(a=2,a=1)  b 3.
            #3.3.1    &&   ||.  ,  
               ,  ()    ,
                     .
           
           
             f1(v[i],i++); //   f2( (v[i],i++) ) //  
           
             f1  , v[i]  i++,    -
           - .   -  -
             -    ,    . 
            f2  ,    ,  
           i++.
           
                       .  ,
           a*(b/c)     (a*b)/c,  *  /  -
            .    ,     ,
              , , (t=b/c,a*t).
           
                3.2.3   *
           
           
             *     ""  "", 
             ,        C,
                C. (. .)
              ++        
                     -
           .   ++lvalue  lvalue+=1,    
            lvalue=lvalue+1  ,   lvalue   -
             .  ,  () -
           ,     ,     ().
           ,     --.   ++   --
                ,    .  
           ++x   (    )    x.  ,
           y=++x  y=(x+=1).   x++,  ,   
            x.  ,  y=x++  y=(t=x,x+=1,t),   t -
              ,   x.
           
                     
             .  ,      
            :
           
             inline void cpy(char* p, const char* q) {
                 while (*p++ = *q++) ;
             }
           
             ,        ,
                 ,   -
             ,      p++ 
            ,   p    .   p 
           T*    :
           
             long(p+1) == long(p)+sizeof(T);
           
                3.2.4   
           
               
           
             & | ^ ~ >> <<
           
             ,      char, short, int, long
             unsigned ,   .
           
                       -
              ( ).     -
                     ,  
               .   & -
             ,  |  ,  ^  . 
                  -
           .   ,    ( -
            ) <stream.h>:
           
             enum state_value { _good=0, _eof=1, _fail=2, _bad=4 };
                              // ,  , , 
           
              _good   .    , 
           ,    ,   .  -
                :
           
             cout.state = _good;
           
             ,   ,       -
             :
           
             if (cout.state&(_bad|_fail)) //  good
           
              ,  &    -
           ,  |.
             ,   ,     :
           
             cin.state |= _eof;
           
            |=  ,       
           ( , state==_bad), 
           
             cin.state = _eof;
           
              .      :
           
             state_value diff = cin.state^cout.state;
           
                stream_state ( )     
            ,          -
           .  ,     ,  -
            ,  ,  , 
           ,  .
           
              ,    (#2.5.1)  -
                   -
               .  ,  ,     
             ,  ,   16  
           32- int   :
           
             unsigned short middle(int a) { return (a>>8)&0xffff; }
           
                     -
             :
           
               && || !
           
               0  1,      
                if, while  for (#3.3.1). -
           ,  !0 ( )   1,    ~0 ( )
              -,     -1.
                3.2.5  
           
                      -
            .        
               . :
           
             float r = float(1);
           
                 1    -
               1.0.          
           lvalue,     (    
            ).
           
                   :  
             C         (double)a   
           double(a).          ,
               . ,   -
                    -
            
           
             char* p = (char*)0777;
           
               :
           
             typedef char*  Pchar;  char*  p  = Pchar(0777);    ,
                 
           .    
           
             Pname n2 = Pbase(n1->tp)->b_name;  //   Pname
             n3 = ((Pbase)n2->tp)->b_name; //    
           
               ->    ,    ,
              
           
             ((Pbase)(n2->tp))->b_name
           
                       
           ,       . -
           :
           
             any_type* p = (any_type*)&some_object;
           
                p     some_object
               any_type.
           
                 ,      .
           ,       ,
            ,   ,      .  
             ,  ,    -
                  (, -
           ,           
           ,   ,      struct  
            , . #2.5.2).  ,   -
                   -
             ,       -
             ,      . :
           
             int i = 1; char* pc = "asdf"; int* pi = &i;
           
             i = (int)pc;  pc = (char*)i;  // !  pc 
             
                               //   
                               // sizeof(int)<sizeof(char*)
             pi = (int*)pc;  pc = (char*)pi; // !  pc -
              
                               //    char*
                               //  ,  int*
           
                   ,     -
             .       -
           .      ,     -
               .   , 
             (   )  void*, 
           void*       .
           
              ++          
           ,  C (  )  .   
                ,     -
                      -
           .
                3.2.6  
           
                 ,  
           (. #2.1.3).       -
                  .  -
                      -
               ,       .  
               ,     , 
                 .   ,    
           ,        ,  
             .      new,   
               delete.  ,   -
              new,  ,      .  
                    
           ,     ,  
                 .  ,  
                    -
           .        
            ,     
           . :
           
             struct enode { token_value oper; enode* left; enode* right;
             };
           
             enode* expr() { enode* left = term();
           
             for(;;) switch(curr_tok) { case PLUS: case MINUS:
                     get_token(); enode* n = new enode;  n->oper  =  curr_tok;
                     n->left = left; n->right = term(); left = n; break;
                 default:
                     return left;
                 }
             }
           
                      
           :
           
             void generate(enode* n) {
                 switch (n->oper) { case PLUS:
                     //   
                     delete n;
                 }
             }
             ,    new, ,     -
             delete,    ,    ,
              new.  " ", 
            ,     ,     -
            new, .  delete     -
           ,       new,    .  
           delete      .
           
               new     . :
           
             char* save_string(char* p) {
                 char* s = new char[strlen(p)+1]; strcpy(s,p); return s;
             }
           
              ,     ,  
           new,  delete      
           . :
           
             int main(int argc, char* argv[]) {
                 if (argc < 2) exit(1); char* p = save_string(argv[1]); delete
                 p;
             }
           
                ,   ,   -
            new,       ,      
           (,    ).
           
                      
           delete. :
           
             int main(int argc, char* argv[]) {
                 if (argc < 2) exit(1);  int size = strlen(argv[1])+1; char* p
                 = save_string(argv[1]); delete[size] p;
             }
           
                   
            ,   (#5.5.5).
           
                  (#.7.2.3):
           
             void operator new(long); void operator delete(void*);
           
               new    .
              ,    new          ?
               ,      -
           .  
           
             char* p = new char[100000000];
           
            ,    - .   new 
             ,      ,      
           _new_handler (     #4.6.9).  
                   set_new_handler().
           :
           
             #include <stream.h>
           
             void out_of_store() {
                 cerr << " new    :      \n";
                 exit(1);
             }
           
             typedef void (*PF)(); //    
           
             extern PF set_new_handler(PF);
           
             main() {
                 set_new_handler(out_of_store); char* p = new char[100000000];
                 cout << ", p = " << long(p) << "\n";
             }
           
            ,     "",     -
           
           
                new  :   
           
              _new_handler    - ,    
             .    ,   new 
           delete,  ,  ,      operator
           new()    operator  delete(),     
              ,    new.  
           ,      ,  , 
           ,   delete  .    ,  ,
           -    .
                new    0,  
                      -
            _new_handler. 
           
             include <stream.h>
           
             main() {
                 char* p  =  new char[100000000];  cout << ",  p = " <<
                 long(p) << "\n";
             }
           
           
           
             , p = 0
           
               ! ,  ,  
           _new_handler,        
                new    (  ,
                  -
             ,  , . #5.5.6).
                3.3  
           
              ++      #.9,  -
           , ,  .      
            .
           
                                       
              
              :
                   {_ opt}  opt
           
                  if  if (  ) 
                  if (  )  else  switch 
              switch (  ) 
           
                  while (    )  do  while ()
                  for (   opt ;  opt ) 
           
                  case _ :    default  :  
                  break ; continue ;
           
                  return  opt ;
           
                  goto  ;  : 
           
                  _:
                        _
           
             ,    ,     
              .     -
             .
           
                3.3.1 
           
                      if,  
            switch:
           
             if (  )  if (  )  else 
             switch (  ) 
           
              ++    .  
           
             == != < <= > >=
           
             1,    ,   0. 
              ,     1,   -
             0.
                if   ( )   
            ,   ,    -
            (  ).  ,     
              .  ,  a , 
           
             if (a) // ...
           
           
           
             if (a != 0) // ...
           
               && || !     -
           .   &&  ||     ,   
           . :
           
             if (p && 1<p->count) // ...
           
            ,    p  ,      ,
             1<p->count.
           
                  if      
             if. :
           
             if (a <= d) max = b;
             else max = a;
           
             :
           
             max = (a<=b) ? b : a;
           
                ,    ,    
           ,   .
           
                switch   -    
              if. :
           
             switch (val) { case 1:
                 f(); break;
             case 2; g(); break;
             default:
                 h(); break;
             }
           
                :
           
             if (val == 1) f();
             else if (val == 2) g();
             else h();
           
               ,      (switch)  ,
                        (-
                ).      
             switch  .
               ,   switch    -  ,  
              ,    case. :
           
             switch (val) { //  case 1:
                 cout << "case 1\n"; case 2;
                 cout << "case 2\n"; default:
                 cout << "default: case  \n";
             }
           
            val==1 
           
             case 1 case 2 default: case  
           
              .    
            -  break,     goto. :
           
             switch (val) { //  case 0:
                 cout << "case 0\n"; case1: case 1:
                 cout << "case 1\n"; return;
             case 2; cout << "case 2\n"; goto case1;
             default:
                 cout << "default: case  \n"; return;
             }
           
                  val==2 
           
             case 2 case 1
           
             ,   case       
            goto:
           
             goto case 1;       //  
                3.3.2 Goto
           
             ++      goto.
           
             goto ;  : 
           
              ,          
           ,      ,  ++  -
            ,     . -
           ,   goto     -
           ,    . 
           goto        ,    -
            ,  ,      -
           ,    .
           
                       -
               (break     -
                 ). -
           :
           
             for (int i = 0; i<n; i++) for (int j = 0; j<m; j++)
                     if (nm[i][j] == a) goto found // 
                                                   //  
             // ...
           
             found:                                // 
             // nm[i][j] == a
           
                continue,       
              ,    #3.1.5.
           
                3.4   
           
                   -
                     
            .     -
             .      -
               (    ,   
            ).       -
           .
           
                    
             ,        
           ,          ,
            
           
             [1] ,
           
             [2]   
           
             [3]  .
           
             ,        -
              .      -
           ,  .
              -     , 
            ,       .   
              :
           
             //  "v"   .
           
             //  "v"     "f()".
           
             //   init()  
             //      .
           
             //    "cleanup()"   
             // .
           
             //    "wierd()".
           
             //  "f()"   .
           
                ++    
            .     ,
           ,  ,       (#4.2)  -
           ,       (. #5.5.2).
           
              -     ,    -
                . :
           
             a = b+c; // a  b+c count++; //  
           
                  ,    
           ,    ,      
           ,     .
              :
           
             [1]     , ,  
                        ,  
                     ,      
                  ..,
           
             [2]     ,   -
                  ,    (  -
                ) ,  , -     -
                   ,
           
             [3]      ,   -
                 /  
           
             [4]    .
           
             :
           
             // tbl.c:   
             /*
                        .  Ralston:  "A first
                 course ..." . 411.
             */
           
             // swap()    AT&T sB20.
           
             /**************************************
           
                 Copyright (c) 1984 AT&T, Inc. All rights reserved
           
             ****************************************/
           
                   - 
            .       
           ,     .
           
              ,          
            //,        
              /* */,  .
                3.5 
           
             1. (*1)    for     
                 while:
           
                  for (i=0;  i<max_length;  i++)  if  (input_line[i]  ==  '?')
                      quest_count++;
           
             2. (*1)      :
           
                  a = b + c * d << 2 & 8 a & 077 != 3 a == b || a == c && c  <
                  5  c  = x != 0 0 <= i < 7 f(1,2)+3 a = -1 + + b -- - 5 a = b
                  == c ++ a = b = c = 0 a[4][2] *= * b ? c : * d * 2 a-b,c=d
           
             3. (*2)     ++,   
                .
           
             4. (*2)      ++ -
                .
           
             5. (*1)     ,       ?
                      ?
           
             6. (*1)      :
           
                  *p++
                  *--p
                  ++a--
                  (int*)p->m
                  *p.m
                  *a[i]
           
             7. (*2)   :  strlen(),      
                ,  strcpy(),        ,  
                strcmp(),     .  ,  
                         ,  
                     ,    
                <string.h>    .
           
             8. (*1) ,      :
           
                  a := b+1; if (a = 3) // ... if (a&077 == 0) // ...
           
                  ,  ,    
                .
             9. (*2)   cat(),    -
                   ,    -
                .    new,      .
                  rev(),     
                     .  ,   rev(p)
                  p  .
           
             10. (*2)    ?
           
                  void send(register* to, register* from, register count)
                  //    .
                  { register n=(count+7)/8; switch (count%8) {
                          case 0:  do { *to++ = *from++;  case 7: do { *to++ =
                          *from++;  case 6: do { *to++ = *from++; case 5: do {
                          *to++ = *from++;  case 4: do { *to++ = *from++; case
                          3:  do { *to++ = *from++;  case  2:  do  {  *to++  =
                          *from++; case 1: do { *to++ = *from++;
                              while (--n>0);
                      }
                  }
           
                 -    ?
             11. (*2)   atoi(),   , -
                  ,        int.  ,
                atoi("123") -  123.   atoi() ,  
                         -
                  ++.   atoi() ,  -
                      .     
                itoa(),         
                .
           
             12. (*2)  get_token() (#3.1.2),       
                   ,     ,  -
                  .
           
             13. (*2)      #3.1  ,
                 sqrt(),  log()  sin().  :   
                       .  
                     .
           
             14. (*3)           
                 .  :     
                 ,   ,    -
                .          -
                  ,      .   ,  
                 ,     .  
                ,      , 
                    .
           
             15. (*1.5)    ,   
                   name_string  number_value -
                   symbol:
           
                  struct symbol { token_value tok; union {
                          double number_value; char* name_string;
                      };
                  };
           
             16. (*2.5)  ,    
                ++ .  ,   cin,  //  /* */ -
                       cout.     
                   (    ,  
                ).     . -
                 //  /*  */  ,     
                .
           
             17. (*2)  - ,    
                        ,   
                  .
                                4   
           
                                                  ,
                                                         .
                                                              - .  
           
                      
              (    ).   
            ,       -
              ,      
            ( ),      
           ,          .  
             .    , -
               ,     ,  ,   ,
              .    .
                4.1 
           
                      ,  
                   -
               .   ,     
                   .  
                     
            ,       -
               .      
           ,    ,      ( 
              ),      .   
              ,     -
           ,            
             .
           
                .       -
             .     ,      
                   ,
                   "" ,
                        
           expr(),  term()   prim().     ,   
               ( ,  -
            ,    ),     -
                .   ,  
            -.    ;     
           " "     -
           ,    ,    -
               200    ,    -
             .
           
             ,        -
           ,         ,
             ,   ,     .
            ,      *.  - 
           ,     . -
             ()  .  UNIX'  -
            ld.   ,     ,
                .
           
                   
           ,      (-
           ).       -
             ,     -
            .  ,   ,   
           .  ++  ,     -
           **.
           
           
           
           *  . (. .)
           
           ** C  ,     
             .  C, ,  -
           ,   ,     -
           ,    . (. )
                4.2 
           
                ,  ,     
            ,    ,  , -
                  , ,   -
           .    ,         ,
           ,       .  , ,
            :
           
             // file1.c:
                 int a = 1; int f() { /* -  */ }
           
             // file2.c:
                 extern int a; int f(); void g() { a = f(); }
           
           a  f(),  g()   file2.c,-  ,   
            file1.c.      extern  ()  ,  
            a  file2.c  () ,    -
           .    a , extern    -
           ,       -
           .            .
                  ,      -
           . :
           
             // file1.c:
                 int a = 1; int b = 1; extern int c;
           
             // file2.c:
                 int a; extern double b; extern int c;
           
               :  a   (int a;  -
           ,    int a=0;), b     -
           ,   c  ,   .     
             ,       
           . , ,  .
           
                 ++  ( C 
           ):
           
             // file1.c:
                 int a; int f() { return a; }
           
             // file2.c:
                 int a; int g() { return f(); }
           
             -, file2.c  ++,   f()   ,  -
              . -, ( file2.c -
           )    ,   a  -
           .
                  ,   static. :
           
             // file1.c:
                 static int a = 6; static int f() { /* ... */ }
           
             // file2.c:
                 static int a = 7; static int f() { /* ... */ }
           
               a  f   static,   -
              .      a    
           f().
           
                     static,   -
              (     ). -
            static   ,   ,    
              ,     -
              .
           
               :
           
             // file1.c:
                 const int a = 6;  inline int f() { /* ... */ } struct s { int
                 a,b; }
           
             // file1.c:
                 const int a = 7;  inline int f() { /* ... */ } struct s { int
                 a,b; }
           
                "    "   ,
           inline-     ,    
              ,  file1.c  file2.c    
            ++ .     ,         
                  ?  ,   :
           ,   ..    ,  -
           ,    ,       .   
              (    ).
           
                4.3  
           
                         -
           .          -
                ,    -
             -    1950-,       
           *.      ,  -
            ,       ,  -
           ,   ,    -
            .   ,    
                   ,
             ,   ,   -
              /  .
           
           
           *    ,     
           ,    ,    -
                ? (. )
                 #include -     
                      
             ()   . 
           
             #include "to_be_included"
           
            ,     #include,   
           "to_be_included".        ++,
                .   -
             ,  C , -
             CC     , 
            ,        ,   -
             .      -
                      ,   
              .     
             ,   
           
             CC -E file.c
           
              file.c  ,    
           CC    .      
                  -
             <  >. :
           
             #include <stream.h>      //    
             #define "myheader.h"     //   
           
              <>     ,     -
                 ( ,  -
             /usr/include/CC,   usr/include).  -
           ,    include :
           
             #include < stream.h > //   <stream.h>
           
              ,        ,
             - ,  ,    
                 ,  
                 .  
           ,       -
            ,    ,      
               ,       -
            .
                 ,   , 
                 ,    -
            ,        -
            #include.
           
                 :
           
                 struct point { int x,  y;  }  
               extern  int  strlen(const  char*);    inline-
               inline  char get() { return *p++;  }   extern int
               a;    const float pi = 3.141593 
               enum   bool   {  false,  true  };    include  #include
               <signal.h>   #define Case break;case -
                /*     */
           
            
           
                  char get() { return *p++; } -
                 int a;       
               const tbl[] = { /*
               ... */ }
           
               UNIX ,          
           () .h.  ,     ,
              .c.     , -
           ,  ".h "  ".c ".   #4.7  .  
           ,    ++        ,      C,
            ++    ,  const  -
              inline      .
           
              ,       -
                ,          
            ,  .   ,    
             ,      -
            (      ).  -
                      
                  .
             ,          
               .
                4.3.1   
           
                     -
                    -
               ,     ,  -
             ,       .
                      .c :
           lex.c,  syn.c, table.c  main.c,    dc.h, -
               ,        .c
           :
           
             // dc.h:    
           
             enum token_value  {  NAME,  NUMBER,  END,  PLUS='+',   MINUS='-',
                 MUL='*', DIV='/', PRINT=';', ASSIGN='=', LP='(', RP=')'
             };
           
             extern int no_of_errors;  extern double  error(char*  s);  extern
             token_value  get_token();  extern  token_value  curr_tok;  extern
             double number_value; extern char name_string[256];
           
             extern double expr(); extern double term(); extern double prim();
           
             struct name { char* string; name* next; double value;
             };
           
             extern name*   look(char*   p,   int   ins  =  0);  inline  name*
             insert(char* s) { return look(s,1);  }    
             ,  lex.c   
           :
           
             // lex.c:    
           
             #include "dc.h"
             #include <ctype.h>
           
             token_value curr_tok; double number_value; char name_string[256];
           
             token_value get_token() { /* ... */ }
           
             ,       -
           ,       , 
           ,    -    ,   -
           .  ,   lex.c   -
           :
           
             extern token_value get_token();
             // ...
             token_value get_token() { /* ... */ }
           
               ,     -
             ,    .  ,   get_token()
                token_value,     
             int,   lex.c        
            .
           
              syn.c    :
           
             // syn.c:    
           
             #include "dc.h"
           
             double prim()  { /* ...  */ } double term() { /* ...  */ } double
             expr() { /* ... */ }
           
              table.c    :
           
             // table.c:    
           
             #include "dc.h"
           
             extern char*  strcmp(const  char*,  const  char*);  extern  char*
             strcpy(char*, const char*); extern int strlen(const char*);
           
             const TBLSZ = 23; name* table[TBLSZ];
           
             name* look(char* p;  int ins) { /* ... */ } ,  table.c
                 
              ,      
            .        ,  
                 .c    extern.     
           " ",          
           ,      ,      
           .     ,      ,
            strlen()    main() ().   
               ,    
                .   -
           ,      ,    extern
             dc.h,    .  "" -
             ,         C  ,
              ,   ,   -
           ,   ,   ,   ,  -
             .  !
           
              main.c, ,  :
           
             // main.c: ,     
           
             #include "dc.h"
           
             int no_of_errors;
           
             double error(char* s) { /* ... */ }
           
             extern int strlen(const char*);
           
             main(int argc, char* argv[]) { /* ... */ }
           
              ,       -
            .       -
                -  
            (.  5-8).       -
                   . -
               ""        -
           .       
              .  ,   -
                    .  
                   -
           .
                4.3.2   
           
                       
                 ,         
             .   ,    
           ,            ,
           .    .    -  
           ,         ,  
                  .  
             .c       .h ,    .c 
              ( ,    )
           .h  , ,   .h  (
           ,   ).
           
               ,   ,   error()
                  ,    
            <stream.h>.      , 
           error()    main():
           
             // error.h:  
           
             extern int no_errors;
           
             extern double error(char* s);
           
             // error.c
           
             #include <stream.h>
             #include "error.h"
           
             int no_of_errors;
           
             double error(char* s) { /* ... */ }
           
                   .h    -
              .c     ,  
           .h   ,  .c   .
           
                        
              .    :
           
             // table.h:   
           
             struct name { char* string; name* next; double value;
             };
           
             extern name*  look(char*  p,  int  ins   =   0);   inline   name*
             insert(char* s) { return look(s,1); }
           
             // table.c:   
           
             #include "error.h"
             #include <string.h>
             #include "table.h"
           
             const TBLSZ = 23; name* table[TBLSZ];
           
             name* look(char* p; int ins) { /* ... */ } ,  
                 
             <string.h>.      
           .
           
             // lex.h:      
           
             enum token_value  {  NAME,  NUMBER,  END,  PLUS='+',   MINUS='-',
                 MUL='*', DIV='/', PRINT=';', ASSIGN='=', LP='(', RP=')'
             };
           
             extern token_value curr_tok;  extern double number_value;  extern
             char name_string[256];
           
             extern token_value get_token();
           
                   .
                    -
              get_token()   -
            number_value  name_string.
           
             // lex.c:      
           
             #include <stream.h>
             #include <ctype.h>
             #include "error.h"
             #include "lex.h"
           
             token_value curr_tok; double number_value; char name_string[256];
           
             token_value get_token() { /* ... */ }
           
                 :
           
             // syn.c:      
           
             extern double expr(); extern double term(); extern double prim();
           
             // syn.c:      
           
             #include "error.h"
             #include "lex.h"
             #include "syn.h"
           
             double prim()  { /* ...  */ } double term() { /* ...  */ } double
             expr() { /* ... */ }  ,  , :
           
             // main.c:  
           
             #include <stream.h>
             #include "error.h"
             #include "lex.h"
             #include "syn.h"
             #include "table.h"
             #include <string.h>
           
             main(int argc, char* argv[]) { /* ... */ }
           
                  ,   
            .        , 
                ,   ++. -
           ,       ,   
             ,     -
             .  ,     
           10   50       ,  
               500 ,     , 
                  -
            .   :       
                    
           .    ,        
                     
           (         ..), 
                  .
                4.3.3  
           
                    
           ,          
           .    ,     ,
             ,   .c   extern.
           
             ,      :
           
             // file1.c: // "extern"  
                 int a = 7; const c = 8; void f(long) { /* ... */ }
           
             // file2.c: // "extern"  .c 
                 extern int a; extern const c; extern f(int); int g() { return
                 f(a+c); }
           
               extern  file2.c      -
               file1.c,      -
             .  ,      
              ,      -
            ,     .
           
                      
           ,  ,      -
           ,   static,       ,   
                . :
           
             // table.c:   
           
             #include "error.h"
             #include <string.h>
             #include "table.h"
           
             const TBLSZ = 23; static name* table[TBLSZ];
           
             name* look(char* p; int ins) { /* ... */ }
           
              ,         table  
              look().  ""   TBLSZ  
           .
                4.4   
           
                .c  .h      -
           .    .h    ,    
            ,  .c   .    -
            .      ,  -
             ,  .    -
             ,    -   ,   
            .      . -
           ,       
           .c ,    .h     
           . ,     ,
              .c .   ,    
            ,     .c ,     -
              .        
            (.o ).
           
                ,    ,    -
               .     
               ,       
           .h ,   ,      
            (),   .h ,     
             ().
           
                   ,   -
             ,    . ,  table -
             ,      ,   -
                   .  
                5.
           
                     -
            ,     () .
                .   ,    -
               ,    -
             ,        ,  /
           ,       
           , . #5.5.2.
                4.5   
           
                "  "  "  - -
           "   (   ,   ),    -
             ++ ?  ,    , 
             ;     , 
              8-   UNIX.    -
             .
           
                   .o , -
                   .c .
                  .h  ,      
                   .o  .    
            ,      ( )  
                    
           .       :
           
             extern double  sqrt(double);  //    <math.h>   extern
             double  sin(double);  extern  double  cos(double);  extern double
             exp(double); extern double log(double);
           
                ,  ,   
           sqrt.c, sin.c, cos.c, exp.c  log.c.
           
                math.h  , , :
           
             $ CC -c sqrt.c sin.c cos.c exp.c log.c
             $ ar cr math.a sqrt.o sin.o cos.o exp.o log.o
             $ ranlib math.a
           
                    
           .     ar,     
           math.a. , ,      .
                ranlib ,    , ,
            .   ,  ,   -
                ar.   ,
           , :
           
             $ CC myprog.c math.a
           
              ,      math.a -
               .o ? :
           
             $ CC myprog.c sqrt.o sin.o cos.o exp.o log.o
           
                    .o  ,
           ,  .         
           ,      myprog.c     sqrt()  
           cos(),  ,   
           
             $ CC myprog.c sqrt.o cos.o
           
              ,  cos.c  sin.c.
           
             ,     CC     .a  (
            ,   math.a) ,    , 
              .a ,   
           .o .
              ,       -
                (    -
           ,      ,     
           ),  ,  , ,     -
                .
           
                4.6 
           
                  -    ++  -  
           ,    .    
            ,     .   
            ,    .
           
                4.6.1  
           
                 ,     
             (    )     ,  
               . :
           
             extern double  sqrt(double);  extern  elem*  next_elem();  extern
             char* strcpy(char* to, const char* from); extern void exit(int);
           
                   .
             ,         
            .  ,     -
           , 
           
             double sr2 = sqrt(2);
           
                sqrt()     -
             2.0.        
           .
           
                  .    -
            ,      .
           
                4.6.2  
           
              ,    ,   - -
            (  ).    -   -
           ,     . :
           
             extern void swap(int*, int*); // 
           
             void swap(int*, int*) //  {
                 int t = *p;
                 *p =*q;
                 *q = t;
             }
           
                   ,    
            inline (#1.12),        -
           ,     register (#2.3.11).   
            ,          
           -    .
                4.6.3  
           
               ,      
            ,     
              .    -
              .  ,  -
                  ,  
                 -
            .          (#4.6.5),
                  (#4.6.8) 
                 (#4.6.6). 
           
             void f(int val, int& ref) {
                 val++; ref++;
             }
           
               f(),  val++     
             ,    ref++   -
            . :
           
             int i = 1; int j = 1; f(i,j);
           
            j,    i.    - i,   -
           ,    - j,   .   
            #2.3.10,   ,      
             ,       ,   
             ( .  #6.5  #8.4).      
                 ,    
            .         const, 
           ,        ,  
                    -
           :
           
             void f(const large& arg) {
                 //  "arg"    
             }
           
             ,     const  -
           ,    ,   ,   
           . :
           
             extern int  strlen(const  char*);  //   <string.h> extern char*
             strcpy(char* to,  const  char*  from);  extern  int  strcmp(const
             char*, const char*);
           
                   .
           
             ,        
           .     const ,  
              ,   (#6.6).
                4.6.4  
           
              ,     void,  ( ) -
             .       return.
           :
           
             int fac(int n) {return (n>1) ? n*fac(n-1) : 1; }
           
                  return:
           
             int fac(int n) {
                 if (n > 1) return n*fac(n-1);
                 else return 1;
             }
           
                 ,    
              .    
                   .
                   -
                   -
             . :
           
             double f() {
                 // ...
                 return 1; //    double(1)
             }
           
              ,     ,     
              .      
             ,     -
             .      
           :
           
             int* f() { int local = 1; // ... return &local; //   
             }
           
                ,     -
            :
           
             int& f() { int local = 1; // ... return local; //   
             }
           
              ,       -
           .   :
           
             int& f() { return 1;} //   
                4.6.5  
           
                   ,  -
                . :
           
             int strlen(const char*);
           
             void f() {
                 char v[] = "a vector" strlen(v); strlen("Nicholas");
             };
           
              ,        T[] -
             T*.  ,    -
               ,    -
           .   ,      
           ,       (   )  -
           .
           
                 .    -
           ,        . 
            ,        .  
                  ,   
           ,   ,     ,
                 (.  #1.11). :
           
             void compute1(int* vec_ptr, int vec_size); //  
           
             struct vec { //   int* ptr; int size;
             };
           
             void compute2(vec v);
           
                 ,        
               ,     
           . :
           
             char* day[] = { "mon", "tue", "wed", "thu", "fri", "sat", "sun"
             };
           
               ,   ,  -
              .      -
           ,    :
           
             void print_m34(int m[3][4]) {
                 for (int i = 0; i<3; i++) { for (int j = 0; j<4; j++)
                         cout << " " << m[i][j]; cout << "\n";
                 }
             }
           
             , ,      ,   -
                .
                      -
             (#2.3.6).         -
           :
           
             void print_mi4(int m[][4], int dim1) {
                 for (int i = 0; i<dim1; i++) { for (int j = 0; j<4; j++)
                         cout << " " << m[i][j]; cout << "\n";
                 }
             }
           
               ,     .
           " "   :
           
             void print_mij(int m[][], int dim1, int dim2) //  {
                 for (int i = 0; i<dim1; i++) { for (int j = 0; j<dim2; j++)
                         cout << " " << m[i][j]; // ! cout << "\n";
                 }
             }
           
             -,   m[][]  ,    
                    -
             .  -,  m[i][j] -
            ()  *(*(m+i)+j),  ,    
            .   :
           
             void print_mij(int** m, int dim1, int dim2) {
                 for (int i = 0; i<dim1; i++) { for (int j = 0; j<dim2; j++)
                         cout << " " << (int*)m[i*dim2+j];  //  cout <<
                     "\n";
                 }
             }
           
             ,       ,  -
            ,    ,    -
             .     ,   
            :
           
             int* v = (int*)m;
             // ...
             v[i*dim2+j]
                4.6.6   
           
                       ,
                    .  ,  
                hex(),     -
             .     
                      .
                  , -
            ,    ,    -
           .        , 
              ,    .  
                    "-
             ,   ".    
              hex(i,0),   :
           
             extern char* hex(long, int =0);
           
                   .
            ,       ,   
              . :
           
             cout << "**" << hex(31) << hex(32,3) << "**";
           
            
           
             cout << "**" << hex(31,0) << hex(32,3) << "**";
           
            :
           
             ** 1f 20**
           
                        
                     .    
                , 
           
             int f(int, int =0, char* =0); // ok int g(int =0, int =0, char*);
             //  int f(int =0, int, char* =0); // 
           
           ,        *  =  -
            (*=   ):
           
             int nasty(char*=0); //  
                4.6.7   
           
              ,      -  ,
                   -
             ,            .
                     
              (overloading).   
              ++:        ,
           +,         ,  
            .        -
           ,   ,   ,  .  
                ,   -
                         
                . :
           
             overload print; void print(int); void print(char*);
           
               ,  ,    
            ,  . ,   - 
           ,        ,    .
             ,      -   
            .        -
              sqrt,  print  open.    
           ,         +, *  << (#6.2) 
               (#5.2.4  #6.3.1),    
           .    f(),  
           ,       f  .  -
                   -
                 f.  ,  
           ,     :
           
             [1]    ,   , 
                 ,
           
             [2]       -
                      
           
             [3]     ,  -
                  (#6.3),    -
                 ,   .
           
             :
           
             overload print(double), print(int);
           
             void f(); {
                 print(1); print(1.0);
             }
                ,   f  1 
             1.0     . , char  short -
             .  ,  float  
           double.
           
                        ++
                 (#.6.6)   -
           .  ,   ,  -
           .  int  long, int  double,   long,   double
             :     void*,
                          
           (#7.2.4).
           
              ,    :
           
             overload print(double), print(long);
           
             void f(int a); {
                 print(a);
             }
           
              a      double,   long. -
                            (
           print(long(a))  print(double(a))).
           
                 ,      
                  -
           ,     (). :
           
             overload pow;  int pow(int,  int); double pow(double, double); //
               <math.h>  complex  pow(double,  complex);  //   <complex.h>
             complex pow(complex,  int); complex pow(complex, double); complex
             pow(complex, complex);
           
                  unsigned  const.
                4.6.8   
           
                      -
           ,     .    -
                (...),     "
            ,  -  ". :
           
             int printf(char* ...);
           
              ,     printf      
           ,  char*,    ,     . -
           :
           
             printf("Hello, world\n");  printf("  %s %s\n",  first_name,
             second_name); printf("%d + %d = %d\n",2,3,5);
           
                 ,   -
                  .    printf()
               ,    
            ,  printf()  -
             . %s  "  char*",  %d
             "  int".  ,     ,
                 ,     
            . :
           
             printf("  %s %s\n",2);
           
                  - 
            .
           
             ,     ,       -
           ,         -
            .     char  short   int, 
           float   double.    ,   -
           .
               ,   wild(...),  
              ,   
               ,      -
             C.       
             ,        -
           .   ,          ,  
                   -
               ,       
             .      -
              ,     .    
                  C ,
                ,    :
           
             extern int fprintf(FILE*,  char* ...); //  <stdio.h> extern int
             execl(char* ...);  //  <sysent.h> extern int abort(...);  // 
             <libc.h>
           
               ,      -
                 ,     <stdargs.h>.
               ,    -
            ,    ,    
             .       ,    
                    
            :
           
             void error(int ...);
           
             main(int argc, char* argv[]) {
                 switch(argc) { case 1:
                     error(0,argv[0],0); break;
                 case 2:
                     error(0,argv[0],argv[1],0); default:
                     error(1,argv[0],"",dec(argc-1),"",0);
                 }
             }
                 :
           
             #include <stdargs.h>
           
             void error(int n ...)
             /*
                 "n"    char*,  
             */
             { va_list ap; va_start(ap,n); //  arg
           
                 for (;;) { char* p = va_arg(ap,char*); if(p == 0) break; cerr
                 << p << " "; }
           
                 va_end(ap); //  arg
           
                 cerr << "\n"; if (n) exit(n);
             }
           
                va_list           
           va_start().  va_start   va_list'   
              .  va_arg  
                 .    
              ; va_arg() ,   -
              ,        .
              ,       va_start(),
               va_end().    ,   va_start() 
             ,         ;
           va_end()    .
           
                4.6.9   
           
                    :      
           .  ,     ,   
               . :
           
             void error(char* p) { /* ... */ }
           
             void (*efct)(char*); //   
           
             void f() {
                 efct = &error;  // efct   error  (*efct)("error");
                 //  error  efct
             }
           
                 ,  , efct,  -
              ,  *efct.   
            ()    ,    -
             *,          *efct("error").    
           *efct("error"),     .      
            (.  #7.3.4).
             ,        
             ,        .    
                 . -
           :
           
             void (*pf)(char*); //   void(char*) void f1(char*); //
             void(char*)  int  f2(char*);  //  int(char*)  void  f3(int*);  //
             void(int*)
           
             void f() {
                 pf = &f1; // ok pf = &f2; // :   
                  pf = &f3; // :    
           
                 (*pf)("asdf"); // ok (*pf)(1); // :    -
                 
           
                 int i = (*pf)("qwer"); // : void  int'
             }
           
                    
                    .
           
             ,    -  -
           ,         --.
           :
           
             typedef int  (*SIG_TYP)();  //      <signal.h>   typedef   void
             (*SIG_ARG_TYP); SIG_TYP signal(int,SIG_ARG_TYP);
           
                       .  ,
                  *      
                 . 
                ,    :
           
             typedef void (*PF)();
           
             PF edit_ops[] = { //   cut,  paste,  snarf,
                 search
             };
           
             PF file_ops[] = { //      open,  reshape,  close,
                 write
             };
           
           
           *  -        
           .   ,     . (. -
           )
                       ,   
           ,   ,     (button) -
           :
           
             PF* button2 = edit_ops; PF* button3 = file_ops;
           
                     
            . , -   , -
            ,   .    -
                   .  -
             ()    -
            .      ,  
           3   2,     :
           
             (button2[3])();
           
                         -
                  .   
               ,     -
            .        
            .
           
                      
           ,    ,     -
              :
           
             typedef int (*CFT)(char*,char*);
           
             int sort(char* base, unsigned n, int sz, CFT cmp)
             /*
                  "n"   "base"   
                    ,   "cmp".   -
                  "sz".
           
                   :  
             */
             { for (int i=0; i<n-1; i++)
                     for (int j=n-1; i<j; j--) { char* pj = base+j*sz; // b[j]
                         char* pj1 = pj-sz; // b[j-1] if ((*cmp)(pj,pj1) < 0)
                             //  b[j]  b[j-1]
                             for (int k=0;  k<sz;  k++) { char temp  =  pj[k];
                                 pj[k] = pj1[k]; pj1[k] = temp;
                             }
                     }
             }
                    ,  
               ( ),    -
               ,      .
             sort()    ,         
             C   qsort().    
           qsort().   sort()   ,    
             void,     ,    qsort(),  
           void  C   .  ,    -
                void*  char*.   -
              ,  ,   
           :
           
             struct user  {  //  char* name;  //  char* id;  //
                  int dept; // 
             };
           
             typedef user* Puser;
           
             user heads[]  =  { //  "McIlroy M.D.",  "doug",  11271,
                 "Aho A.V.",  "ava",  11272,  "Weinberger P.J.", "pjw", 11273,
                 "Schryer N.L.",  "nls",  11274, "Schryer N.L.", "nls", 11275,
                 "Kernighan B.W.", "bwk", 11276
             };
           
             void print_id(Puser v, int n) {
                 for (int i=0; i<n; i++) cout << v[i].name << "\t"
                         << v[i].id << "\t"
                         << v[i].dept << "\n";
             }
                ,    -
             .      -
            ,      , ,
             ,      :
           
             int cmp1(char* p, char* q) //   name {
                 return strcmp(Puser(p)->name, Puser(q)->name);
             }
           
             int cmp2(char*p, char* q) //   dept {
                 return Puser(p)->dept-Puser(q)->dept;
             }
           
                 :
           
             main () {
                 sort((char*)heads,6,sizeof(user),cmp1); print_id(heads,6); //
                                     cout      <<      "\n";
                 sort((char*)heads,6,sizeof(user),cmp2); print_id(heads,6); //
                   
             }
           
                inline-,  , ,   -
            (#.8.9).
                4.7 
           
             *   #.11.  C   ,   ++ -
             .      : 
            ,       .    ,
                    ,    -
           .     , , ,
                  C -
           .
           
                :
           
             #define name rest of line
           
              name   ,       rest  of
           line. :
           
             named = name
           
             :
           
             named = rest of line
           
                  . :
           
             #define mac(a,b) argument1: a argument2: b
           
               mac     . 
            mac()   a  b. :
           
             expanded = mac(foo bar, yuk yuk)
           
             
           
             expanded = argument1: foo bar argument2: yuk yuk
           
                   ++    ,
                 ++    - .   
              ,        -
              ,      .   -
                 .
           
           
           *    . (. .)
                  :
           
             #define Case break;case
             #define nl <<"\n"
             #define forever for(;;)
             #define MIN(a,b) (((a)<(b))?(a):(b))
           
                :
           
             #define PI 3.141593
             #define BEGIN {
             #define END }
           
                 :
           
             #define SQUARE(a) a*a
             #define INCR_xx (xx)++
             #define DISP = 4
           
              ,    ,     
            :
           
             int xx = 0; //  
           
             void f() { int xx = 0; //   xx = SQUARE(xx+2);
                 //  xx  =  xx+2*xx+2 INCR_xx;  //   xx if
                 (a-DISP==b) { // a-= 4==b
                     // ...
                 }
             }
           
                  ,     
                 :: (#2.1.1)
                   ,  
             (. MIN ).
           
                       
           :
           
             #define m1(a) something(a) //  
             #define m2(a) something(a) /*   */
           
           ,
           
             int a = m1(1)+2; int b = m2(1)+2;
           
            
           
             int a = something(1) //  +2;  int b  =
             something(1) /*   */+2;
           
                       .
            ,      .  , C
             -   .    
            - ,  , , ,  -
              ,    ( . #7.3.5).
                4.8 
           
             1. (*1)   : ,  
                            
                ;     ; ,  -
                     ;   ,  
                 .   ,  -
                         
                 . :  typedef.
           
             2. (*1)   ?     ?
           
                  typedef int (rifii&) (int, int);
           
             3. (*1.5)    "Hello,  world",  -
                             "Hello,
                ".     ,    -
                      hello   .
           
             4. (*1.5)   ,     
                ,        ,
                       cout.     
                   ,      cat
                ().
           
             5. (*2)   C   ++.   -
                  ,        
                   .  ,   , -
                 #define  enum  const  inline.   .c -
                   extern      -
                 ++.     malloc()    free()    new  
                delete.    .
           
             6. (*2)  sort() (#4.6.7)   
                .
           
             7. (*2)    struct tnode  .#8.5. 
                        tnode. 
                     tnode.      
                   tnode     . -
                 tnode ,     () 
                    ,     new  -
                 .      
                 tnode.
           
             8. (*2)    "",    .    .h 
                  push(), pop()     
                ().  .c    ,  
                 .
           
             9. (*2) ,       .
                      ,       /usr/include  
                /usr/include/CC ( ,     -
                    ).   ,   -
                .
             10. (*2)      .
           
             11. (*2)     ,    
                cin    cout  .    -
                    :  -
                  c -  c^key[i],   key () - , 
                    .  
                  key ,      . -
                        key 
                 .      ( -
                  ),     .
           
             12. (*3)     ,      
                ,     ,   .
                : David Kahn: The Code-Breakers, Macmillan, 1967, New
                York, pp 207-213.
           
             13. (*3)   error,    -
                   printf,     %s,  %c  %d, 
                  .     printf().
                          %s  ..,   #8.2.4.
                 <stdarg.h>.
           
             14. (*1)          ,
                   typedef?
           
             15. (*2)      -   ,    
                     ,   
                .           ?  
                 ?       x
                 y?
           
             16. (*1)     ?
           
                  #define PI = 3.141593
                  #define MAX(a,b) a>b?a:b
                  #define fac(a) (a)*fac((a)-1)
           
             17. (*3)  ,     
                  ( C ).    cin  
                 cout.       -
                .  :     (#3.1)  
                    ,     -
                .
                                           5 
           
                                                        "",
                                          ,  int  float.
                                                               -  
           
                        
           ++,             
            .       ,  
           ,     ,  ,   . 
                     ,  
           ,            (
           , "") .     -
                 ++   -
                .
                              5.1    
           
                ,          
            ,    ,    
                ,      
              .       ,
                 , -
             .
           
                    ().
           ,   ++  float    +, -, *  ..
            ,     -
              .      ,  
                ,    
                   .  ,  
           ,     ,     
           trunk_module ( ),      - 
           list_of_paragraphs ( ).   ,  , 
             ,     , -
            ,   ,      .  -
             ,    ,    
             .      -
             ,     -
               .
           
                   -  
             (,   ,  -
               )   ,  
               (,   ,
               ).     ,
                      
                 (-
           ).
                    :
           
             #5.2   .      
                ,   ,     
                (class).       
                ,      .  
                  .      -
                    ,       
                .       .  
                       "" -
                     .   -
                 .
           
             #5.3   .     
                 ,   ,   -
                .
           
             #5.4   .     
                 ,  .   -
                ,          ,
                     .   -
                  (friend).     ,  -
                  .
           
             #5.5   .    
                ,       .
                          (
                  ),       
                     .      
                   .
           
                5.2   
           
              -    .    
               ,   ,
                ,  ,    
            .
                5.2.1  
           
                      struct 
           ,      date   
                :
           
             struct date { int month, day, year; };
                 // : , ,  }
             date today;   void   set_date(date*,   int,   int,   int);   void
             next_date(date*); void print_date(date*); // ...
           
                        .  
             ,    :
           
             struct date { int month, day, year;
           
             void set(int, int, int); void get(int*, int*, int*); void next();
             void print(); };
           
             ,   ,     
                 
                    
           . :
           
             date today; //  date my_burthday; //   
           
             void f() {
                 my_burthday.set(30,12,1950); today.set(18,1,1985);
           
                 my_burthday.print(); today.next();
             }
           
                     -
            ,        
           :
           
             void date::next() {
                 if ( ++day > 28 ) {
                     //    
                 }
             }
           
                      -
             .         , 
              .
                5.2.2 
           
              date        
               date,      ,        
                   date.    
               struct class:
           
             class date { int month, day, year;
             public:
                 void set(int,  int,  int);  void get(int*,  int*, int*); void
                 next(); void print();
             };
           
              public:         .    ,
            ,     . -
           ,   ,     . Struct
           -   class,       ,  
                  ,    -
            . :
           
             void date::ptinr() //   ,    {
                 cout << month << "/" << day << "/" year;
             }
           
                     -
             date. :
           
             void backdate() {
                 today.day--; // 
             }
           
              ,            
            ,    .  , 
              ,       (-
           ,  36, 1985)      , -
              ,  ,    ,
              .       -
           ,       date    -
               .    -  , 
                    
             ,    .
           
                     
            .        , 
            , , .
                5.2.3   
           
                  ,      ,
             . :
           
             class x { int m;
             public:
                 int readm() { return m; }
             };
           
             x aa; x bb;
           
             void f() {
                 int a = aa.readm(); int b = bb.readm(); // ...
             }
           
                 member() m   aa.m,     -
            bb.m.
           
               ,      , 
               .        -
               this.      x   this
             
           
             x* this;
           
             ,     ,   -
              .  this     ,    
               .    x    
           :
           
             class x { int m;
             public:
                 int readm() { return this->m; }
             };
                  this .    
           this     ,  -
             .      -  ,
                :
           
             class dlink { dlink* pre; //  dlink* suc; // -
                 
             public:
                 void append(dlink*);
                 // ...
             };
           
             void dlink::append(dlink* p) {
                 p->suc = suc;  //  ,  p->suc = this->suc p->pre = this;
                 //     this  suc->pre  =  p;  //    ,
                 this->suc->pre = p suc = p; //  , this->suc = p
             }
           
             dlink* list_head;
           
             void f(dlink*a, dlink *b) {
                 // ...
                 list_head->append(a); list_head->append(b);
             }
           
                           
           ,      7.    
              ,     
           this,  pre  suc (,    ).   
           dlink,        dlink::append()    .
              ++  class,     .
                5.2.4 
           
                    -
             set_date() ( )     -
           .     ,     -
           ,        ,    (
           ,  ,     ) -
             .     :   -
               ,     
           .       -
           ,   .    ,
               ,    . :
           
             class date {
                 // ...
                 date(int, int, int);
             };
           
                  ,       
           .         ,  
            :
           
             date today = date(23,6,1983);  date xmas(25,12,0); // 
             
                                     // (xmas - )
             date my_burthday; // ,  
           
                     
            .    ,    .
           :
           
             class date { int month, day, year;
             public:
                 // ...
                 date(int, int, int); //    date(char*); //  
                   date(int);  // ,     -
                  date(); //   : 
             };
           
                    -
           ,     (#4.6.7).   -
                ,    
               :
           
             date today(4);  date  july4(" 4,  1983");  date guy("5 ");
             date now; //   
           
             ,            
                 overload.    
                     ,
                       
           overload         
           .
                  date .  -
                  "",   
             -     ,    
           -    ,     ,   -
           ,      .    -
           ,     ,     
            .       
           -      ,  .  -
            date         ,
             "  : today" ().
           
             class date { int month, day, year;
             public:
                 // ...
                 date(int d =0,  int m =0,  int y =0);  date(char*); //  
                  
             };
           
             date::date(int d, int m, int y) {
                 day = d ?  d : today.day; month = m ? m : today.month; year =
                 y ? y : today.year; // ,    // ...
             }
           
                  ,    "  
           ",        -
             .    day   mounth ,   
           ,     year   .   ,    -
                   .    1 .   ..
           (year==-1)  1 .  .. (year==1),     
              .
           
                        
                .      
           ,   . :
           
             date d = today; //   
           
              ,     ,   
                .       X  
                 ,     
              X(X&).     #6.6.
                5.2.5 
           
                       ,      ,
           ,       .  
                ,  ,  
                .    -
              X  ~X() (" ").  -
           ,          
            (.  #3.2.6),     -
            . , ,   ,  -
                 :
           
             class char_stack { int size; char* top; char* s;
             public:
                 char_stack(int sz) { top=s=new char[size=sz]; }
                 ~char_stack() { delete s; } // 
                 void push(char  c)  {  *top++  =  c;  }  char  pop() { return
                 *--top;}
             }
           
              char_stack     ,   -
           :
           
             void f() {
                 char_stack s1(100);    char_stack    s2(200);   s1.push('a');
                 s2.push(s1.pop());  char ch = s2.pop();  cout <<  chr(ch)  <<
                 "\n";
             }
           
               f(),   char_stack    s1,
                 100 ,    s2,   
             200 .     f()     
           .
                5.2.6 Inline
           
                    -
               .   ,  ,    
                     -   
             ,  . ,   -
           ,   ,   .  
             ,     
           (         )   
            ,     ,    -
           .
           
                    ,        
           inline-.  ,    (    ) 
            ,   inline.   ,  ,    
           ,     char_stack,  -
               ,     
            !  ,     -
           ,          .
           ,     ,   . 
             ,      -
                .
           
                    inline   .
           :
           
             char char_stack { int size; char* top; char* s;
             public:
                 char pop();
                 // ...
             };
           
             inline char char_stack::pop() {
                 return *--top;
             }
                5.3   
           
                 ?  ,   
              . ,   -
               "  ",     
             . ,    -
               ,     -
             . ,      -
           .
           
                   :
           , ,  ,  ,    ..   
             "",        -
            ,        .        
                    
           ,     ,        
            .    ( , ) 
              .
           
                      -
            (.  #4.4:   ). , , 
           .    ,       
           ,        ,   .
               .    ,   
            ,     .
                5.3.1  
           
                         
             ,        
              .          
           ,          3.
             :
           
             struct name { char* string; char* next; double value;
             };
           
              table:
           
             //  table.h
           
             class table { name* tbl;
             public:
                 table() { tbl = 0; }
           
             name* look(char*,  int  =  0);  name*  insert(char*  s)  { return
             look(s,1); } };
           
                 ,      3 ,
               .       table,  
              table  .. :
           
             #include "table.h"
           
             table globals; table keywords; table* locals;
           
             main() { locals = new table; // ...
             }
           
               table::look(),     
              name  :
           
             #include <string.h>
           
             name* table::look(char* p, int ins) {
                 for (name* n = tbl;  n; n=n->next) if (strcmp(p,n->string) ==
                     0) return n;
           
                 if (ins == 0) error("  ");
           
                 name* nn = new  name;  nn->string  =  new  char[strlen(p)+1];
                 strcpy(nn->string,p);  nn->value = 1;  nn->next = tbl;  tbl =
                 nn; return nn;
             }
                table,   ,
              ,     -
              .    -  -
           ,       ,    
                table,   -
             :
           
             class table { name** tbl; int size;
             public:
                 table(int sz = 15);
                 ~table();
           
             name* look(char*,  int =  0);  name*  insert(char*  s)  {  return
             look(s,1); } };
           
                     ,  
            ,      -
              .      
            ,    ,     -
             ,   .   
              ,        
            .       -
            -:
           
             table::table(int sz) {
                 if (sz < 0) error("  ");  tbl = new
                 name*[size=sz]; for (int i = 0; i<sz; i++) tbl[i] = 0;
             }
           
             table::~table() {
                 for (int i = 0;  i<size;  i++) for  (name*  n  =  tbl[i];  n;
                     n=n->next) {
                         delete n->string; delete n;
                     }
                     delete tbl;
             }
                 name      
             table::~table().     -
            ,      -
            (#3.1.3):
           
             #include <string.h>
           
             name* table::look(char* p, int ins) {
                 int ii = 0;  char* pp = p; while (*pp) ii = ii<<1 ^ *pp++; if
                 (ii < 0) ii = -ii; ii %= size;
           
                 for (name* n=tbl[ii];  n;  n=n->next) if (strcmp(p,n->string)
                     == 0) return n;
           
                 if (ins == 0) error("  ");
           
                 name* nn = new  name;  nn->string  =  new  char[strlen(p)+1];
                 strcpy(nn->string,p);  nn->value  =  1;  nn->next  = tbl[ii];
                 tbl[ii] = nn; return nn;
           
             }
           
             ,        
           ,     -    .  
                    
           .   ,   .    -
                  .   -
              ,  ,    ,
             .      (  
             ),     () ,
                    
           ,        .
             ,   , ++  ,   -
                        
           ?   ,       
              ?   ,  
                     ,    
                  ,  ,  
           ,  ?  - .  -
                ,    ,
             ,  ,    -
            (  )    .
           
                  ,     
              "" .       -
              ,   ""  -
              ,     ,     
            .     
                 ,   ,      ,
                     
                   
           .        inline-
           ,      .  , -
                     C  ++
            ( C   struct    ,  
              ++ ).  ++    -
           .
           
                5.3.2  
           
                   (    )
               ,     
            (  ).       
               ,     .  
             ,     -
                 ;    
           .  ,     ,  -
                 .
           
                   intset,    
           " ":
           
             class intset { int cursize, maxsize; int *x;
             public:
                 intset(int m, int n); //  , m int'  1..n
                 ~intset();
           
                 int member(int   t);   //       t  ?  void
                 insert(int t); //  "t"  
           
                 void iterate(int& i) { i = 0;  }  int  ok(int&  i)  {  return
                 i<cursize; } int next(int& i) { return x[i++]; }
             };
                ,     -
              .      -
             .       -
                   .    
                   -
           .  ,  :
           
             #include <stream.h>
           
             void error(char* s) {
                 cerr << "set: " << s << "\n"; exit(1);
             }
           
              intset   main(),     -
            .       , -
             .     ,  -
               :
           
             main(int argc, char* argv[]) {
                 if (argc != 3) error("  ");  int count =
                 0;  int m = atoi(argv[1]); //    int n
                 = atoi(argv[2]); //   1..n intset s(m,n);
           
                 while (count<m) { int t = randint(n); if (s.member(t)==0) {
                         s.insert(t); count++;
                     }
                 }
           
                 print_in_order(&s);
             }
           
              ,      ,   
           ,  argc,    ,    
              argv[0]. 
           
             extern int atoi(char*);
           
            atoi()       -
                      (-
           ) .           
            rand():
           
             extern int rand(); //   ,  
           
             int randint(int u) //   1..u {
                 int r = rand(); if (r < 0) r = -r; return 1 + r%u ;
             }
                   -
                 ,       
            .        -
             ,    :
           
             intset::intset(int m, int n) //  , m int'  1..n {
                 if (m<1 || n<m) error("  intset");  cursize
                 = 0; maxsize = m; x = new int[maxsize];
             }
           
             intset::~intset() {
                 delete x;
             }
           
               ,       -
           :
           
             void intset::insert(int t) {
                 if (++cursize > maxsize)  error("    ");
                 int i = cursize-1; x[i] = t;
           
                 while (i>0  &&  x[i-1]>x[i])  { int t = x[i];  // 
                     x[i]  [i-1] x[i] = x[i-1]; x[i-1] = t; i--;
                 }
             }
           
                 :
           
             int intset::member(int t) //   {
                 int l = 0; int u = cursize-1;
           
                 while (l <= u) { int m = (l+u)/2; if (t < x[m])
                         u = m-1; else if (t > x[m])
                         l = m+1; else
                         return 1; // 
                 }
                 return 0; //  
             }
             , ,      ,  -
                      ,
             intset     .  
                 ,      
                ( , , 
           intset -,    ).
           
                :  iterate()   ,  ok()
            ,     ,   next()  , 
             :
           
             class intset {
                 // ...
                 void iterate(int&  i)  {  i  =  0;  } int ok(int& i) { return
                 i<cursize; } int next(int& i) { return x[i++]; }
             };
           
                       
            ,    ,      
           .       , 
            .         
            print_in_order:
           
             void print_in_order(intset* set) {
                 int var;  set->iterate(var);  while  (set->ok(var))  cout  <<
                 set->next(var) << "\n";
             }
           
                 #6.8.
                5.4   
           
                    ,  
           .  ,        -
            . ,     , 
               ,    -
            .   ,      -
              ,       
           .  ,    ,  ,   
            () .
           
                5.4.1 
           
             ,    ,  vector  matrix ( 
           ).       
                 .  
           ,    .   ,  
             ,   0...3,   
              ,  0...3.  ,
                   elem(),
              ,     matrix  -
            .           
            multiply() ()   :
           
             vector multiply(matrix& m, vector& v); {
                 vector r; for (int i = 0; i<3; i++) { // r[i] = m[i] * v;
                     r.elem(i) = 0; for (int j = 0; j<3; j++)
                         r.elem(i) += m.elem(i,j) * v.elem(j);
                 }
                 return r;
             }
           
                "" ,     .
               multiply() elem()   4*(1+4*3)
           .
             ,    multiply()   vector,   -
                     -
           ,     multiply()   matrix,   
                      .
                        .    
             ,        
            .    ,     
            ,    (friend).  
                friend. :
           
             class matrix;
           
             class vector { float v[4]; // ... friend vector multiply(matrix&,
                 vector&);
             };
           
             class matrix   {   vector   v[4];   //    ...    friend    vector
                 multiply(matrix&, vector&);
             };
           
                  ,    
              .   , friend    -
            this (        -
           ).  friend -  .    
                    -
              .     
            ,       .  , -
             .
           
                 ,    -
               :
           
             vector multiply(matrix& m, vector& v); {
                 vector r; for (int i = 0; i<3; i++) { // r[i] = m[i] * v;
                     r.v[i] = 0; for (int j = 0; j<3; j++)
                         r.v[i] += m.v[i][j] * v.v[j];
                 }
                 return r;
             }
                     
             friend (     -
                 multiply()   ).   -
             ,     ,   -
                  , -
                .    6   
            friend.       -
            .
           
                    . :
           
             class x {
                 // ...
                 void f();
             };
           
             class y {
                 // ...
                 friend void x::f();
             };
           
                 ,       
               .        -
           :
           
             class x { friend class y; // ...
             };
           
                friend      y 
           x.
                5.4.2 *  
           
                      
             .      ::, "
            ":
           
             class x { int m;
             public:
                 int readm() { return x::m; } void setm(int m) { x::m = m; }
             };
           
              x::setm()   m   m,    
                   -      
           x::m.     ::    .
           
                ::  ()     .  
                 ,       
              read,  put  open    ,
                    ,  -
              . :
           
             class my_file {
                 // ...
             public:
                 int open(char*, char*);
             };
           
             int my_file::open(char* name, char* spec) {
                 // ...
                 if (::open(name,flag)) { //  open()  UNIX(2)
                     // ...
                 }
                 // ...
             }
           
           
           *    . (. .)
                5.4.3  
           
                 . :
           
             class set { struct setmem {
                     int mem;  setmem* next; setmem(int m, setmem* n) { mem=m;
                     next=n; }
                 };
                 setmem* first; public:
                 set() {   first=0;   }   insert(int   m)   {   first   =  new
                 setmem(m,first);} // ...
             };
           
                      ,   
             .   ,   -  
                ,      -
                  :
           
             class set { struct setmem {
                     int mem; setmem* next; setmem(int m, setmem* n)
                 };
                 // ...
             };
           
                 setmem::setmem(int m,  setmem* n)  {  mem=m,  next=n}  setmem
                 m1(1,0);
           
              ,  set::setmem::setmem(),    -
           ,   .        -  
                -- (#4.4).  
               :
           
             class setmem { friend class set;  //     -
              set
                 int mem;  setmem* next;  setmem(int m,  setmem* n)  {  mem=m;
                 next=n; } };
           
             class set { setmem* first;
             public:
                 set() {   first=0;   }   insert(int   m)   {   first   =  new
                 setmem(m,first);} // ...
             };
                5.4.4  
           
              -  ,     ,       
               ,    . 
                ,      
                 ()  -
           .  ,       
             .  ,     
                     :
           
             class task {
                 // ...
                 task* next;  static task* task_chain; void shedule(int); void
                 wait(event); // ...
             };
           
               task_chain ( )  static  -
           ,         ,        
            task.         task,
             ""     ,      
            public.              
           :
           
             task::task_chain
           
                   task_chain.  -
                  
             .
           
                5.4.5   
           
                   .     
             ,     ,  -
             #4.6.9    ,    
               .  ,      
            :      , -
                .    -
             ,  .   ,
             ,    ,      -
           .      ,    
                       
           ,    .   
            ,       this      
           ()   *:
           
           
           *    ++     :
           cl::*  "    cl". :
             typedef void (cl::*PROC)(int); PROC pf1 = &cl::print; // -
                 PROC pf2 = &cl::print;
           
                     
           .  ->. :
           
             (z1.*pf1)(2); ((&z2)->*pf2)(4);
           
           (. )
           
             #include <stream.h>
           
             struct cl {
                 char* val;  void print(int x) { cout << val << x << "\n";  };
                 cl(char* v) { val = v; }
             };
           
             // ``''    :
             typedef void (*PROC)(void*, int);
           
             main() {
                 cl z1("z1 ");  cl z2("z2 "); PROC pf1 = PROC(&z1.print); PROC
                 pf2   =    PROC(&z2.print);    z1.print(1);    (*pf1)(&z1,2);
                 z2.print(3); (*pf2)(&z2,4);
             }
           
                      
           (.   7) ,       
           .
           
                5.4.6   
           
               struct -   ,    -
           ,  
           
             struct s { ...
           
              
           
             class s { public: ...
           
                 ,     -
           .
                   struct,    
                  (. #.8.5.13).  , 
                    , 
              .  ,  -
                 C :
           
             union tok_val  { char* p;  //  char v[8];  // 
                 ( 8 char) long i; //   double d; // -
                    
             };
           
                ,  ,  ,  ,
                 ,   
             . :
           
             void strange(int i) {
                 tok_val x; if (i)
                     x.p = "2"; else
                     x.d = 2; sqrt(x.d); //   i != 0
             }
           
            ,  ,  ,  ,  -
           . :
           
             tok_val curr_val = 12; // : int  tok_val'
           
            .     ,      ,  
            :
           
             union tok_val { char* p;  //  char v[8];  //  
                 ( 8 char) long i; //   double d; // -
                    
           
                 tok_val(char*); //    p  v tok_val(int ii)
                 { i = ii; } tok_val() { d = dd; }
             };
           
                  ,      
                     (.
           #4.6.7  #6.3.3). :
           
             void f() {
                 tok_val a = 10; // a.i = 10 tok_val b = 10.0; // b.d = 10.0
             }
                (  ,  char*  char[8], int 
           char,   ..),          
                     -
            . :
           
             tok_val::tok_val(char* pp) {
                 if (strlen(pp) <= 8) strncpy(v,pp,8); //  
                 else p = pp; //  
             }
           
             -  .
           
                    
              tok_val,      
             ,       .  
                ,   -
           ,    :
           
             class tok_val { char tag;
             union { char* p;  char v[8];  long i; double d; }; int check(char
                 t, char* s)
                     { if (tag!=t) { error(s); return 0; } return 1; } public:
                 tok_val(char* pp);   tok_val(long  ii)  {  i=ii;  tag='I';  }
                 tok_val(double dd) { d=dd; tag='D'; }
           
                 long& ival() { check('I',"ival");  return i; } double& fval()
                 {   check('D',"fval");   return   d;   }   char*&   sval()  {
                 check('S',"sval");  return p; } char* id() { check('N',"id");
                 return v; }
             };
             ,   ,    -
              strncpy().  strncpy()   strcpy(), 
             ,  ,   -
            :
           
             tok_val::tok_val(char* pp) {
                 if (strlen(pp)   <=  8)  {  //      tag  =  'N'
                     strncpy(v,pp,8); //  8 
                 }
                 else { //   tag = 'S';  p = pp; //  -
                      
                 }
             }
           
              tok_val   :
           
             void f() {
                 tok_val t1("short");  //  ,      v   tok_val
                 t2("long string");  //  ,  p char s[8];
                 strncpy(s,t1.id(),8); // ok strncpy(s,t2.id(),8); // 
                 check()  
             }
                5.5   
           
                  ,     ,  
             .     ,   -
            ,    .   -
            :
           
             [1]  :   ,   -
                    ,    -
                     ,    ;
           
             [2]  :    ,   -
                ,    ,   ;
           
             [3]    :     new 
                    delete;
           
             [4]  :        -
                .
           
                          
              (.  #6.4),      -
            .     , 
             ,    . -
               table  #5.3.
                5.5.1 
           
              x  y -   cl,  x=y    -
              y  x (.  #2.3.8).  
                (  )
           ,        ,   
              . :
           
             class char_stack { int size; char* top; char* s;
             public:
                 char_stack(int sz) { top=s=new char[size=sz]; }
                 ~char_stack() { delete s; } // 
                 void push(char c) { *top++ = c; } char pop() { return *--top;
                 }
             };
           
             void h() {
                 char_stack s1(100);  char_stack  s2  =  s1;  //  
                 char_stack s3(99); s3 = s2; // 
             }
           
              char_stack::char_stack()    :   s1  
           s3.  s2   ,    -
            .   char_stack::~char_stack() -
            :  s1, s2  s3!  ,   -
                ,   
            h()   s1, s2  s3     
           ,        s1.  -
                ,    -
            s3.    : .  6.
                5.5.2  
           
              :
           
             table tbl1(100);
           
             void f() { static table tbl2(200);
             }
           
             main() {
                 f();
             }
           
                table::table(),    #5.3.1,  
            :     tbl1     tbl2. -
            table::~table()    :   tbl1
            tbl2    main().      -
                  ,   -
            ;     . -
           ,        -
           ,   ,      ,   .
                 , 
              ,       
               .
           
                        
            :
           
             void g(int a) {
                 static table t(a); // 
             }
           
                     main().
                ,    C,     
               /      -
                    ,    -
             /   main().
           
                    -
             ++   .     
                  .  
           <stream.h>.    cin, cout  cerr?    -
           ?  ,    ,      
             ,      ? 
              ,     -
                    main().
                   ,
               .   
             ,   .
                   exit(),   -
                ,    
             abort(),    .  ,    ,
            exit()    .   exit()   -
                .
           
             ,    ,   
                 , 
              :    .    
               ,    -
            ,     .
           
                5.5.3  
           
             :
           
             main() {  table*  p = new table(100);  table* q = new table(200);
                 delete p; delete p; // , 
             }
           
              table::table()   ,    
           table::~table(). ,  ++    ,   -
           ,    new, -   ,
             .     q   ,    p
            !      ,  
             ,      p  q.  ,   
           ,    ,      .
            p  ,   ,  . 
              delete      
                 ,  
                  ,   
            .
           
                      new  
           delete (.  #3.2.6).      
                new  delete (. #5.5.6)
           
                5.5.4    
           
             
           
             class classdef  {  table  members;  int  no_of_members;  //   ...
                 classdef(int size); ~classdef();
             };
                 ,   classdef  
             size   members,    -    ,  
            ,    table::table()   -
            size.   :
           
             classdef::classdef(int size)
             : members(size)
             { no_of_members = size; // ...
             }
           
                 (  table::table()) -
              (  )  , -
               (  classdef::classdef()).    
               ,    -
           .
           
                    ,          
           ,    . :
           
             class classdef { table members; table friends; int no_of_members;
                 // ... classdef(int size); ~classdef();
             };
           
                   (  -
           ),           
            :
           
             classdef::classdef(int size)
             : friends(size), members(size)
             { no_of_members = size; // ...
             }
           
             ,    ,  , 
                  :
           
             classdef::classdef(int size)
             : friends(size=size/2), members(size); //  
             { no_of_members = size; // ...
             }
                     ,   -
                   .  ,  
           table::table       15,  
             :
           
             classdef::classdef(int size)
             : members(size)
             { no_of_members = size; // ...
             }
           
             size  friends   15.
           
                ,        ,   (,
           classdef) ,      -
            ,     .
           
                ,      
              ,  -       
           :
           
             class classdef   {   table*   members;   table*   friends;    int
                 no_of_members; // ... classdef(int size); ~classdef();
             };
           
             classdef::classdef(int size) {
                 members =  new  table(size);  friends = new table;  // 
                    no_of_members = size; // ...
             }
           
                      new,    -
              delete:
           
             classdef::~classdef() {
                 // ...
                 delete members; delete friends;
             }
           
                    -
           ,   ,  members  friends    -
           ,             
            .   ,      -
              ,   .
                5.5.5   
           
                 ,   , 
              ,     
           .      . -
           :
           
             table tblvec[10];
           
            ,    table::table()   .
                  . 
                    table,   
            table (#5.3.1), , :
           
             class table {
                 // ...
                 void init(int sz); //    public:
                 table(int sz) //  ,      { init(sz);
                     }
                 table() //   { init(15); }
             }
           
               ,      -
              .  ,    -
              new,    .      -
                  ,   -
                      -
              . :
           
             void f() {
                 table* t1 = new table;  table* t2 = new table[10]; delete t1;
                 //   delete t2; // : 10 
             }
           
                  :
           
             void g(int sz) {
                 table* t1 = new table;  table* t2 = new table[sz]; delete t1;
                 delete[] t2;
             }
           
                       
             ?  ,    -
                    .
                5.5.6  
           
                  ,   -
            ,     ,     
                    .  
            -       
           ,         ,  
                    -
                  .
           
               name,        table.
                :
           
             struct name { char* string; name* next; double value;
           
                 name(char*, double, name*);
                 ~name();
             };
           
                ,     -
                  -
             (  ,   ),     -
            new  delete.      ,    -
               ""   name,     ,
                     -
            .  nfree    -
            name:
           
             const NALL = 128; name* nfree;
           
             ,   new,   
               ,        
           delete.    ,      ,
                .  ,    
                name 16 , -
                      20
           .     :
           
             name::name(char* s, double v, name* n) {
                 register name* p = nfree; //  
           
                 if (p) nfree = p->next;
                 else { //      name*  q  =  (name*)new  char[
                     NALL*sizeof(name) ];  for (p=nfree=&q[NALL-1];  q<p; p--)
                     p->next = p-1; (p+1)->next = 0;
                 }
           
                 this =  p;  //   string = s;  value = v;
                 next = n;
             }
               this    ,  -
              ,       -
              .  name::name() -
               ,   name   new,
                  .    #5.5.8  ,
                     
           ,     .
           
             ,   
           
             name* q = new name[NALL];
           
             ,         -
           ,  new  name::name().
           
                :
           
             name::~name() {
                 next = nfree; nfree = this; this = 0;
             }
           
                this  0    ,  
               .
           
                5.5.7 
           
                  this,    this
              .   ,    
                       -
           .          ,  
             this     -
           :
           
             mytype::mytype(int i) {
                 if (i) this = mytype_alloc();
                 //  
             };
           
           ,    i==0          .
               ,      new,
            .    new,   this    -
             ,      this   ,
                 (,    ).    
             ,   ,  ( -
            )     new. :
           
             mytype::mytype(int i) {
                 if (this == 0) this = mytype_alloc();
                 //  
             };
           
              ,        
           ,        new,  ,  
            ,    ,    delete,  
            ,    .   -
             ,      - 
             .      -    
           ,           -
            .      , 
               .
           
              ,      ,        
            ,      , 
                .    
              ,    ,    ,
            .
                5.5.8   
           
                   -
            ,     ,   -
             .        
           (   - .)  vector,  stack,  intset  table
                 ,  -
               .   ,   
                    
               ,        
               . :
           
             class char_stack { int size; char* top; char* s;
             public:
                 char_stack(int sz) { top=s=new char[size=sz]; }
                 ~char_stack() { delete s; } // 
                 void push(char c) { *top++ = c; } char pop() { return *--top;
                 }
             };
           
                    ,  -
             .   :
           
             class char_stack { int size; char* top; char s[1];
             public:
                 char_stack(int sz);  void  push(char c) { *top++ = c;  } char
                 pop() { return *--top; }
             };
           
             char_stack::char_stack(int sz) {
                 if (this) error("    ");  if (sz  <  1)
                 error("      <   1");  this  =  (char_stack*)  new
                 char[sizeof(char_stack)+sz-1]; size = sz; top = s;
             }
           
             ,     ,  , -
             char_stack,    delete   -
              .
                5.6 
           
             1. (*1)        3,  
                  table.
           
             2. (*1)    tnode (#.8.5)    ,
                  ..    tnode'   
                ,   ..
           
             3. (*1)   intset (#5.3.2)   .
           
             4. (*1)      intset    node,  
                node -   .
           
             5. (*3)    ,  ,   -
                      ,     
                   +,  -,  *  /.     
                  :
           
                  class expr {
                      // ...
                  public:
                      expr(char*); int eval(); void print();
                  }
           
                   expr::expr()  .
                  expr::eval()         ,   
                expr::print()      cout.  -
                  , , :
           
                  expr x("123/4+123*4-3"); cout << "x = " << x.eval() << "\n";
                  x.print();
           
                  expr  :      
                   ,     - -
                 .      -
                :     ,    
                ,     ..
           
             6. (*1)      char_queue ( ) 
                ,       .
                  char_queue  (1)     (2) -
                .    .
           
             7. (*2)   histogram (),     -
                      ,   -
                    histogram.   
                   .   , -
                  . : <task.h>.
             8. (*2)    ,   
                     .      
                ,   ,   draw,
                  "" .  : <task.h>.
                   intset.
           
             9. (*2)       date  (#5.8.2),    char_stack
                (#5.2.5)   intset (#5.3.2)     
                (   ).    class
                 friend.    ,    -
                 .
           
             10. (*3)  -     
                     .  ,   -
                    ,    
                .
           
             11. (*2)      5 , 
                     =. 
                     10.
           
             12. (*1)  :
           
                  #include <stream.h>
           
                  main() {
                      cout << "Hello, world\n";
                  }
           
                 ,   
           
                  Initialize Hello, world Clean up
           
                     main().
                               6  
           
                                                         !
                                                            -  
           
                  ,    ++  -
            .       
                    .   -
           ,       ,  -
           ,   ()   [],    
             .      -
                   .
           ,   ,      
                  
            .
                6.1 
           
                 ,   -
              .  ,   int 
           ++    +,  -, *, /  ..  
           ()    .    
                ,  ,  
                .  ,
                 
              . ,  ,  
           ,  ,      -
               ++.        
           ++            
           ,      .  -
            ,      , -
                    
               ,    ,      
               . :
           
             class complex { double re, im;
             public:
                 complex(double r,  double i) { re=r;  im=i;  } friend complex
                 operator+(complex,       complex);       friend       complex
                 operator*(complex, complex);
             };
           
                ,  
                      -
           ,        +  *
           ( ).     +  *   -
                operator+  operator*.  ,  ,
             b    c    complex,    b+c    (  )
           operator+(b,c).      -
             . :
           
             void f() {
                 complex a  = complex(1,  3.1);  complex b = complex(1.2,  2);
                 complex c = b;
           
                 a = b+c; b = b+c*a; c = a*b+complex(1,2);
             }
           
                ,    
            b=b+(c*a),   b=(b+c)*a.
                6.2  
           
                ,     -
           :
           
             + - * / % ^ & | ~ !
             = < > += -= *= /= %= ^= &=
             |= << >> >>= <<= == != <= >= &&
             || ++ -- [] () new delete
           
                -      (#6.7),    
           (#6.8),        
           (#3.2.6).        ,
                 .  ,  ,
              %   !.  
              ,     ,    -
             ,      
           .   ,  **,  pow().   -
              ,       
              . ,    -
             **,     ,   -
               ,    .  
           **      (  )   (  )?
             a**p        a*(*p)     
           (a)**(p)?
           
                   operator ( ,  -
           ),       ,  ,  operator<<.
                   ,   
            .    -     -
               . :
           
             void f(complex a, complex b) {
                 complex c =  a  +  b;  //      complex  d  =
                 operator+(a,b); //  
             }
           
               complex     -
            .
                6.2.1    
           
                     , -
             ,     ,   -
           .  ,     @ aa@bb  -
                         aa.operator@(bb),        
           operator@(aa,bb).    ,   aa@bb  .
            ,   ,   
              ,    ,      
           ,    .   ,    
             @  aa@    @aa            
           aa.operator@(),   operator@(aa).    ,  -
           ,   aa@,  @aa  .   -
           :
           
             class X {
             // 
           
                 friend X   operator-(X);   //         friend    X
                 operator-(X,X);  //    friend X operator-();  //
                 :    friend X operator-(X,X,X);  // :
                 
           
             //  (   : this)
           
                 X* operator&();  //  & ( ) X operator&(X);
                 //  & ( ) X operator&(X,X);  // : -
                 
           
             };
           
                ++   -- ,    
             .
                6.2.2   
           
               ,   ,  -
             .  ,   -
           ,   =     -
           ,    ,  ,  
             lvalue (#.6).
           
                    -
                   -
           . ,  a  int,  ++a  a+=1,   
             a=a+1.      -
              ,      , 
                .  , 
           operator+=  ()   complex      -
            complex::operator+()  complex::operator=().
           
                 =    &    
              .     " -
           "     .   ,  , 
                     X.   ,   ,   
           X::operator&(),        .    -  
               X,    
           *.  ,   ,   X::operator&()
           ,       .
           
           ____________________
           *      "",  ,
                  .    
              . ( )
                6.2.3     
           
                  ,     
                  (,  -
             new  delete,    ). 
            ,       -
             ,       
           .  ,   ,  
             .
           
              ,     -
             ,     . , -
           ,    aa   2: aa+2,  -
               ,    -
               aa.operator+(2),    2+aa     ,
                int,       -
            + ,     2.operator+(aa).    -
             ,   ,    2+aa  aa+2, -
                  .      
            +,   ,      ,
             ,    2+aa  aa+2.   -
                .
           
                  .  
                   ,
                        
           ,        ,  
           ,        (. #4.6.7).
                6.3    
           
                     -
           ,       -,      
           .        .
           :
           
             class complex { double re, im;
             public:
                 complex(double r, double i) { re=r; im=i; }
           
                 friend complex operator+(complex,  complex);  friend  complex
                 operator+(complex,  double); friend complex operator+(double,
                 complex);
           
                 friend complex operator-(complex,  complex);  friend  complex
                 operator-(complex,  double); friend complex operator-(double,
                 complex); complex operator-() //  -
           
                 friend complex operator*(complex,  complex);  friend  complex
                 operator*(complex,  double); friend complex operator*(double,
                 complex);
           
                 // ...
             };
           
             ,   complex,   :
           
             void f() {
                 complex a(1,1), b(2,2), c(3,3), d(4,4), e(5,5); a = -b-c; b =
                 c*2.0*c; c = (d+e)*a;
             }
           
                   complex  double,  
              operator+(),   .  , -
                   -
                 . , , 
            complex,   <complex.h>.
                6.3.1 
           
                     ()
             ,     double -
            complex. :
           
             class complex {
                 // ...
                 complex(double r) { re=r; im=0; }
             };
           
             ,    ,   -
            :
           
             complex z1 = complex(23); complex z2 = 23;
           
            z1,  z2    complex(23).
           
              -  ,     -
           .     ,        
             ,  ,      
           ,  . ,  complex 
              :
           
             class complex { double re, im;
             public:
                 complex(double r, double i = 0) { re=r; im=i; }
           
                 friend complex  operator+(complex,  complex);  friend complex
                 operator*(complex, complex);
             };
           
            ,           complex  
           ,    .    -
             complex    . , a=b*2 -
           :
           
             a=operator*( b, complex( double(2), double(0) ) )
           
                  
            ,    .
           
             ,          
           ,        
           ,     ,     -
           .
                6.3.2  
           
                    -
            ,    ,     -
           :
           
             [1]         -
                     (     -
                 )
           
             [2]        ,  
                  
           
             [3]      ,    
                 .
           
                 ,     -
            ,        -
           .     X::operator T(),   T -  ,  
             X  T.  ,    tiny (-
           ),        0...63, 
                     -
           :
           
             class tiny  {  char  v;  int assign(int i) { return v = (i&~63) ?
                 (error(" "),0) : i; }
             public:
                 tiny(int i) { assign(i);  } tiny(tiny& i) { v =  t.v;  }  int
                 operator=(tiny& i) { return v = t.v; } int operator=(int i) {
                 return assign(i); } operator int() { return v; }
             }
           
                ,  tiny 
           int,  ,    int.  tiny  -
                .    
               tiny         ,   
           tiny::operator int(),    tiny  int. ,
              ,   int,  tiny, 
             int. :
           
             void main() {
                 tiny c1 = 2; tiny c2 = 62; tiny c3 = c2 - c1; // c3 = 60 tiny
                 c4 = c3; //    () int i = c1
                 + c2; // i = 64 c1 = c2 + 2 * c1; //  : c1 = 0
                 (  66) c2 = c1 -i; //  : c2 = 0 c3 = c2; //
                    ()
             }
                tiny    ,    
            .        -
           ,    .
           
                  -   -
           ,       (-
              100,  ,      
           ,  -   ..).    
             ,  +  *.
           
                    
             ,   (  -
            ) ,          
              .
           
              istream  ostream    , 
              , 
           
             while (cin>>x) cout<<x;
           
               cin>>x   istream&.    -
              ,     cin,  
                 while  (.  #8.4.2).
                     ,  
              ,   .
                6.3.3 
           
                (   )  X -
            ,        X,  
                   
            X.
           
                       
                 -
           .    ;     -
             ,    .   
                    .  
             . :
           
             class x { /* ...  */ x(int);  x(char*);  };  class y { /* ...  */
             y(int); }; class z { /* ... */ z(x); };
           
             overload f; x f(x); y f(y);
           
             z g(z);
           
             f(1); //  :     f(x(1))      f(y(1))
             f(x(1));  f(y(1));  g("asdf"); // : g(z(x("asdf"))) 
              g(z("asdf"));
           
                  
             ,      . :
           
             class x { /* ... */ x(int); } overload h(double), h(x); h(1);
           
                      h(double(1)),  
            h(x(1)),       .  -
                    
               ,   #4.6.7.
                      -
             ,     ,   
             .     .
                   -
           ,     ;   ,    
                ,   
            .  ,   ,   -
              ,    .  -
                      
           .           
            (  ),     
                .        -
               .    ,   
                  ,
                ,     -
              complex.
           
                       
                    .  ,  
              ,          
           aa=f(1),     aa   . 
           aa  x,  ,    x,  -
            ,  -  f(x(1)),    aa -  y,  
              f(y(1)).     
               g("asdf"),      
            g(z(x("asdf"))).     ,   
                ,   -
                .    -
             ,        
             ,      ,
               ..      -
               , ,   ,  -
             !
           
                6.4 
           
                     ,  
            1.2  12e3    double.   , -
           ,        ,   
                .    
                 ,      .  
               inline,   
                     .  ,  ,  
           <comlpex.h>            comlpex,       
           zz1*3+zz2*comlpex(1,2)    ,    .   
                *,    +   -
           ,       comlpex(3)  comlpex(1,2),
             inline.
                6.5  
           
                   comlpex  ,  
           ,   ,    ,   -
              .      double
           ,       .   ,   
                .    -
            ,     ,  
             . :
           
             class matrix { double m[4][4];
             public:
                 matrix(); friend matrix operator+(matrix&,  matrix&);  friend
                 matrix operator*(matrix&, matrix&);
             };
           
                ,   -
               ,   -
           .   ,     -
                 .  
              :
           
             matrix operator+(matrix&, matrix&); {
                 matrix sum; for (int i=0; i<4; i++)
                     for (int  j=0;  j<4;  j++)  sum.m[i][j]  = arg1.m[i][j] +
                         arg2.m[i][j];
                 return sum;
             }
           
              operator+()    +  ,  -
             .       -
           :
           
             class matrix {
                 // ...
                 friend matrix& operator+(matrix&,  matrix&);  friend  matrix&
                 operator*(matrix&, matrix&);
             };
           
               ,       -
           .          
               ,        -
            .       -
              ,       -
           .   ,     .  -
                (   -
           ,     )   .
                6.6   
           
                  string:
           
             struct string { char* p;  int size; //  ,  
                  p
           
                 string(int sz) { p = new char[size=sz]; }
                 ~string() { delete p; }
             };
           
              -     ,      
             .      
           .  ,     #5.10,     
           . :
           
             void f() {
                 string s1(10); string s2(20); s1 = s2;
             }
           
               ,     s1=s2  
                   .   
           f()  s1  s2        
                 .  
               ,     -
               string:
           
             struct string { char* p;  int size; //  ,  
                  p
           
                 string(int sz) { p = new char[size=sz]; }
                 ~string() { delete p; }
                 void operator=(string&)
             };
           
             void string::operator=(string& a) {
                 if (this == &a) return;  //  s=s; delete p; p=new
                 char[size=a.size]; strcpy(p,a.p);
             }
           
               string ,     
             .     f() -
                   :
           
             void f() {
                 string s1(10); s2 = s1;
             }
                 ,   .  -
                      
              .     string::operator=()
           ,       :   p 
                   .  
               ,     -
           .   ,  ,     -
           . ,   ,  , ,
             :
           
             struct string { char* p;  int size; //  ,  
                  p
           
                 string(int sz) { p = new char[size=sz]; }
                 ~string() { delete p; }
                 void operator=(string&); string(string&);
             };
           
             void string::string(string& a) {
                 p=new char[size=a.size]; strcpy(p,a.p);
             }
           
                X     X  
           X(X&).      ,    -
             -    .       
           .   X   X(X&),  -
               ,    -
              ,    
            :
           
             class X {
                 // ...
                 X(something); //   :       X(&X);  //
                 :        operator=(X&);   //
                 :    ~X(); // : 
             };
           
                ,    :   -
               .   , -
                  -  
           .     .   
               ,    .  -
               X(X&),   :
           
             string g(string arg) {
                 return arg;
             }
           
             main() {
                 string s = "asdf"; s = g(s);
             }
             ,    g()  s   "asdf".  -
               s   arg   :  
              string(string&).     
            g()     string(string&);    -
              ,   -
            s.   , ,    
            string::~string()   .
           
                6.7 
           
                      ,  
            operator[].   ()  operator[] -
              .     -
              ..         #2.3.10,
                    
                  .   
           .      :
           
             struct pair { char* name; int val;
             };
           
             class assoc { pair* vec; int max; int free;
             public:
                 assoc(int); int& operator[](char*); void print_all();
             };
           
              assoc    pair  max.      -
                free.  -
            :
           
             assoc::assoc(int s) {
                 max = (s<16) ? s : 16; free = 0; vec = new pair[max];
             }
                      -
            ,     #2.3.10.     
           assoc :
           
             #include <string.h>
           
             int assoc::operator[](char* p)
             /*
                     "pair":
                  p,        "pair"  -
                  "pair",  p  
             */
             { register pair* pp;
           
                 for (pp=&vec[free-1];         vec<=pp;        pp--)        if
                     (strcmp(p,pp->name)==0) return pp->val;
           
                 if (free==max) { // :    pair*
                     nvec  =  new  pair[max*2];  for  ( int i=0;  i<max;  i++)
                     nvec[i] = vec[i]; delete vec; vec = nvec; max = 2*max;
             }
           
                 pp =   &vec[free++];   pp->name   =   new  char[strlen(p)+1];
                 strcpy(pp->name,p);  pp->val = 0;  //   :  0
                 return pp->val;
             }
           
               assoc ,      -
           .      ,    
           ,       :
           
             vouid assoc::print_all() {
                 for (int i = 0;  i<free;  i++) cout << vec[i].name << ": " <<
                     vec[i].val << "\n";
             }
           
            , ,    :
           
             main() //       {
                 const MAX  =  256;  //          char
                 buf[MAX];   assoc   vec(512);  while  (cin>>buf)  vec[buf]++;
                 vec.print_all();
             }
                6.8  
           
              ,     (_), 
              ,     
             ,     .   -
             operator()       
             .        -
                    -
               ,      -
           ,             
           .
           
                 assoc     .
             ,    assoc_iterator,  
             ,        
           assoc.      ,     assoc,
              :
           
             class assoc { friend class assoc_iterator;
                 pair* vec; int max; int free;
             public:
                 assoc(int); int& operator[](char*);
             };
           
             
           
             class assoc_iterator{ assoc* cs;  //   assoc int  i;
                 //  
             public:
                 assoc_iterator(assoc& s)   {   cs  =  &s;  i  =  0;  }  pair*
                 operator()()
                     { return (i<cs->free)? &cs->vec[i++] : 0; }
             };
           
               assoc_iterator   assoc,  -
                      pair   
            ,       ().  -
                0:
           
             main() //       {
                 const MAX  =  256;  //          char
                 buf[MAX];   assoc   vec(512);  while  (cin>>buf)  vec[buf]++;
                 assoc_iterator next(vec); pair* p; while ( p = next() )
                     cout << p->name << ": " << p->val << "\n";
             }
                         
           ,      :      
                  .      -
           ,       
           .
           
             ,        
                    .    
               ,   first(),  next() 
           last() (,   ).
           
                6.9  String
           
                   string.    -
                    
                      
           ++.
           
             #include <stream.h>
             #include <string.h>
           
             class string { struct srep {
                     char* s; //    int n; //  
             };
                 srep *p;
           
             public:
                 string(char *);  // string x = "abc" string();  // string  x;
                 string(string   &);   //   string  x  =  string  ...  string&
                 operator=(char *);  string& operator=(string  &);  ~string();
                 char& operator[](int i);
           
                 friend ostream&    operator<<(ostream&,    string&);   friend
                 istream& operator>>(istream&, string&);
           
                 friend int   operator==(string&   x,   char*    s)    {return
                     strcmp(x.p->s, s) == 0; }
           
                 friend int   operator==(string&   x,   string&   y)   {return
                     strcmp(x.p->s, y.p->s) == 0; }
           
                 friend int   operator!=(string&   x,   char*    s)    {return
                     strcmp(x.p->s, s) != 0; }
           
                 friend int   operator!=(string&   x,   string&   y)   {return
                     strcmp(x.p->s, y.p->s) != 0; }
           
             };
               ( ):
           
             string::string() {
                 p = new srep; p->s = 0; p->n = 1;
             }
           
             string::string(char* s) {
                 p = new srep;  p->s = new char[ strlen(s)+1  ];  strcpy(p->s,
                 s); p->n = 1;
             }
           
             string::string(string& x) {
                 x.p->n++; p = x.p;
             }
           
             string::~string() {
                 if (--p->n == 0) { delete p->s; delete p;
                 }
             }
           
              ,        .
                 () :
           
             string& string::operator=(char* s) {
                 if (p->n > 1) { //   p->n--; p = new srep;
                 }
                 else if (p->n == 1) delete p->s;
           
                 p->s = new char[ strlen(s)+1 ];  strcpy(p->s,  s);  p->n = 1;
                 return *this;
             }
           
              ,       
            :
           
             string& string::operator=(string& x) {
                 x.p->n++; if (--p->n == 0) {
                     delete p->s; delete p;
                 }
                 p = x.p; return *this;
             }
                ,   
            .       (  -
            <<,   ):
           
             ostream& operator<<(ostream& s, string& x) {
                 return s << x.p->s << " [" << x.p->n << "]\n";
             }
           
                      
            (#8.4.1).
           
             istream& operator>>(istream& s, string& x) {
                 char buf[256];  s >> buf;  x = buf;  cout << "echo: " << x <<
                 "\n"; return s;
             }
           
                     -
           .   :
           
             void error(char* p) {
                 cerr << p << "\n"; exit(1);
             }
           
             char& string::operator[](int i) {
                 if (i<0  ||  strlen(p->s)<i)  error("    ");
                 return p->s[i];
             }
           
                    .
                   ,      .
                 ,        
           done,          ,    
             .          
             .
           
             main() {
                 string x[100]; int n;
           
                 cout << " \n"; for (n = 0; cin>>x[n]; n++) {
                     string y;  if (n==100) error("  "); cout
                     << (y = x[n]); if (y=="done") break;
                 }
                 cout << "   \n";  for (int i=n-1; 0<=i;
                 i--) cout << x[i];
             }
                6.10   
           
             , ,    ,       
                 ,
                 -  .         :
           ,     (.  -
           ),      .
           
                X:
           
             class X {
                 // ...
                 X(int); int m(); friend int f(X&);
             };
           
                   f(X&)   
               X::m()  (  ),      
            X.   X::m()     "
           ",          f()    ,
                . :
           
             void g() {
                 1.m(); //  f(1); // f(x(1));
             }
           
              ,    ,   -
           ,     .      ,
                 lvalue (=, *=, ++,
           *=  ..),     .
           
              ,        -
            ,       ,  
           .      ,   -
           ,         lvalue  
             (+, -, ||  ..).
           
                   ,   ,
                   ,    
           ,     ,  .  
                  -
           . , ,     -
             m  m.inv(). ,  inv()  -
             m,      ,  m,
              .
           
                 ,    :
             ,  - -   -
           .   ,     
               .       
            ,     ;  -
                 .   ,   
                  .    
              ,      -
             this.        ,  
               .
                6.11 
           
                     ,  -
                  ,    -
           .  ,     -
                 ,      
           . , ,    
           ,   ,    +  -
              .
           
                 /  
             ,     -
                     
           int,    ,      
           .
           
              ,      
           ,      .   -
           ,        ++ 
                  ,  
              .
           
                6.12 
           
             1. (*2)     string.   -
                  +   "  " +=.  
                  string         -
                ?
           
             2. (*1.5)          ()  
                   .
           
             3. (*3)    string  ,      
                      . -
                  ,        
                    ,    ,     
                 .
           
             4. (*2)   string ,   , -
                   ..     ,  ,
                   ,    -
                    sring.
           
             5. (*3)     string    
                ,        -
                .  ,     
                ,        .  
                      ,  -
                     .
           
             6. (*4)   string    , -
                     ,   -
                   .
             7. (*2)       -
                 :
           
                  struct X { int i; X(int); operator+(int);
                  };
           
                  struct Y { int i; Y(X); operator+(X); operator int();
                  };
           
                  X operator* (X,Y); int f(X);
           
                  X x = 1; Y y = x; int i = 2;
           
                  main() {
                     i + 10;  y + 10;  y + 10 * y; x + y + i; x * x + i; f(7);
                     f(y); y + y; 106 + y;
                  }
           
                 X  Y ,       . -
                  ,          
                  .
           
             8. (*2)    INT,       
                int. :  INT::operator int().
           
             9. (*1)   RINT,       
                int   ,     -
                 + (  ),  - (  ),  *, /, %.
                :   INT::operator int().
           
             10. (*3)   LINT,     RINT,  -
                 ,      64 .
           
             11. (*4)  ,      -
                 .  :     -
                 ,      string.
             12. (*2)  ,     
                     .  : 
                 INT + ,     -,   ,    -
                   int  INT. 
                  ,    -
                         -
                   .
           
             13. (*3)      ,    
                   .    
                ,       .   
                    ,   .
           
             14. (*2)    comlpex (#6.3.1),  tiny (#6.3.2)  
                string (#6.9)   friend .   
                 .      . 
                  ,      .  
                  5.3.
           
             15. (*2)   vec4     float. -
                 operator[]  vec4.    +,  -, *, /, =,
                +=, -=, *=, /=        -
                .
           
             16. (*3)   mat4     vec4.  -
                  mat4 operator[],   vec4.  
                     .  ,
                  mat4  .
           
             17. (*2)   vector,   vec4,   ,
                                        
                vector::vector(int).
           
             18. (*3)   matrix,   mat4,   -
                ,                      
                matrix::matrix(int,int).
                                 7  
           
                                      
                                                                   - . 
           
                     ++.  -
              ,      
                          
                   -
                 .      
                    -
              ,        
               .     
               ,      -
               ,    
              .      -
                     
           .        , -
               .
                                        7.1 
           
                        
            (,    ,     -
                 ),     
                   .
           ,          , 
               .  ,    -
             ( )    ,  -
            ,     ..,   ,  
                   ,
           -      ,      
            .  ,     
               ()        
             .
           
                   ,   
                   -
            ,     ,   ,  
           ,       /  -
           ,           -
              ( ,    ..), 
                 .      ++,
             #7.2,        -
           ,             
            . , , ,   -
                   ,   
              .
           
                -  ,    -
                ,     -
            .  ,     
              ,      ,
               ,     ,    
                     -
            .
           
                7.2  
           
                         
           ,          
            .      ,     
               ,      
           (  ).      -
              ,  ,  ,  -
            .
           
                7.2.1   
           
               ,         ,
              .       -
              :
           
             struct employee { //  char* name;  //  short  age;  //
                  short department; //  int salary; // -
                  employee* next; // ...
             };
                       next.
              :
           
             struct manager { //  employee emp;  //   
                    employee* group; //   // ...
             };
           
                    ;       
           employee     emp  manager.  
             ,   ,  ,    
            emp  .     (manager*)  -
               (employee*),    -
             ,    , .  , 
               ,      -
            .      manager*    
           ,         emp,     
                .    
            ,  ,      
            :
           
             struct manager : employee { employee* group; // ...
             };
           
           manager    employee ,  , employee 
              manager.    manager      
           group    employee (name, age  ..).
           
                employee    manager       
            ,      . -
           :
           
             void f() {
                 manager m1,  m2;  employee e1,  e2;  employee* elist; elist =
                 &m1;  //    m1,  e1,  m2  e2  elist m1.next = &e1;
                 e1.next = &m2; m2.next = &e2; e2.next = 0;
             }
           
                  ,  manager*  -
             employee*.     -
           ,   employee*  manager* .
                7.2.2  
           
                 employee  manager    
                   ,   ,
               . :
           
             class employee { char* name; // ...
             public:
                 employee* next; void print(); // ...
             };
           
             class manager : public employee {
                 // ...
             public:
                 void print();
                 // ...
             };
           
                 .     -
               manager         
           employee?       employee    
                  manager?    
            employee         
           manager?          
           ,    ?
           
             :
           
             void manager::print() {
                 cout << "  " << name << "\n";
                 // ...
             }
           
                     -
                ,            
           ,      .  ,   
             this,  ()    name -
            this->name.   manager::print  
           ,            
                 ,    name
           .
           
                ,     -
           :          -
             .  ,   
                      -
            ,        . -
            ,         ,
             ,          .
                     -
               ,      
            ,    ,    ,
            ..         .
               ,      friend, 
                ,   
             (   #5.3). :
           
             class employee { friend void manager::print(); // ...
             };
           
               manager::print(), 
           
             class employee { friend class manager;
                 // ...
             };
           
                employee      
           manager.       ,         name      
           manager::print().
           
             ,       
           -       . :
           
             void manager::print() {
                 employee::print();  //    
                 // ...              //    
             }
           
           ,    ::,   print()  -
             manager.     . -
               :
           
             void manager::print() {
                 print(); //    
                 // ... //    
             }
           
            ,     manager::print() -
                .
                7.2.3 
           
              employee      (public)     
           manager   :
           
             class manager : public employee {
                 // ...
             };
           
              ,      employee   
              manager. :
           
             void clear(manager* p) {
                 p->next = 0;
             }
           
            ,      next -    employee 
           manager'.    -        (private)
           ,       public:
           
             class manager : employee {
                 // ...
             };
           
              ,     employee  
             manager.   ,    manager 
                    employee,   
             manager   .  , 
                 manager  clear()  
           .           
             ,    .
           
             ,   ,       
              ,  ,    
               . ,  , 
               .
                struct,     -
             public  .  ,
           
             struct D : B { ...
           
           
           
             class D : public B { public: ...
           
              ,         ,
             class,  public  friend,     -
                   struct.    
           ,    ,     ,  
               .
           
                ,   ,   -
                . :
           
             class manager : employee {
                 // ...
             public:
                 // ...
                 employee::name; employee::department;
             };
           
           
           
             _ :: _ ;
           
              ,       
                .   name  department 
             manager',   salary  age -  .  ,
                   
            .         
             .
           
             ,  ,      
                ,   
             ,     () 
            .   ,      
             ,    
              .
                7.2.4 
           
                derived     base,
              derived     
            base     .  -
           ,   base    derived,   .
           :
           
             class base { /* ... */ }; class derived : public base { /* ... */
             };
           
             derived m; base* pb = &m; //   derived* pd =
             pb;  // :  base*   derived* pd = (derived*)pb; //
              
           
              ,          
                   . -
            .
           
              base     derived,  -
             derived*  base*   .   
                 ,     
            base      base,   -
              derived:
           
             class base { int m1;
             public:
                 int m2; // m2 -   base
             };
           
             class derived : base {
                 // m2 -    derived
             };
           
             derived d; d.m2 = 2; // : m2     base*
             pb = &d;  // :  ( base) pb->m2 =  2;  //  ok  pb  =
             (base*)&d; // ok:   pb->m2 = 2; // ok
           
               ,   ,   
                 . ,   
           ,      "". 
            ,     -
                  ,  -
            ,     .  ,  ,  
                  
           m1.             
             .
                7.2.5  
           
                   . :
           
             class employee { ... }; class secretary : employee { ... }; class
             manager :  employee { ...  }; class temporary : employee { ... };
             class consultant :  temporary { ... }; class director : manager {
             ...  }; class vice_president : manager { ... }; class president :
             vice_president { ... };
           
                      
           .          
           ,           -
             . :
           
             class temporary { ...  }; class employee { ... }; class secretary
             : employee { ... };
           
             //  ++:
             class temporary_secretary :  temporary : secretary { ... }; class
             consultant : temporary : employee { ... };
           
                 ,      -
                  .   -
             ,        -
            . :
           
             class temporary { ...  }; class employee { ... }; class secretary
             : employee { ... };
           
             // :
             class temporary_secretary :  secretary { temporary temp;  ...  };
             class consultant : employee { temporary temp; ... };
           
                       ,  
                 .  ,
             consultant             temporary,
           consultant'       (temporary
           employee),     .      
               .
                7.2.6   
           
                  .    -
               ,    ,    
              ,   . :
           
             class base {
                 // ...
             public:
                 base(char* n, short t);
                 ~base();
             };
           
             class derived : public base { base m;
             public:
                 derived(char* n);
                 ~derived();
             };
           
                    -
              .     
               ,      
           (. #5.5.4). :
           
             derived::derived(char* n) : (n,10), m("member",123) {
                 // ...
             }
           
                 :  , 
           ,      .     
           :     ,      -
           .
           
                7.2.7  
           
                      -
              ,        :
                   base*,        
              ?    
              :
           
             [1] ,         
                 (#7.3.3),
           
             [2]      ,    -
                  
           
             [3]    (#7.2.8).  -
                  
             ( ) : , ,
             ..      1    ,  
               .   2  3  
              ,     (-
               )    .   3 - 
              2   .
           
                     , 
             2.         -
            :
           
             enum empl_type { M, E };
           
             struct employee { empl_type type;  employee*  next;  char*  name;
                 short department; // ...
             };
           
             struct manager : employee { employee* group; short level; // -
                 
             };
           
            ,     ,   -
              :
           
             void print_employee(employee* e) {
                 switch (e->type) { case E:
                     cout << e->name << "\t" << e->department << "\n";
                     // ...
                     break; case M:
                     cout << e->name << "\t" << e->department << "\n";
                     // ...
                     manager* p = (manager*)e; cout << "  " << p->level
                     << "\n"; // ... break;
                 }
             }
           
               ,    :
           
             void f() {
                 for (; ll; ll=ll->next) print_employee(ll);
             }
               ,   , 
            ,      ,  -
                ,    -
              .         
            .   -     ,  -
                case    switch,   
            .     ,  
              ,      -
           ,    ,    
           ,     .       
            - ,     print()   -
            ,     ,   
           . :
           
             void print_employee(employee* e) {
                 cout << e->name << "\t" << e->department << "\n";
                 // ...
                 if (e->type == M) { manager* p = (manager*)e;  cout << " -
                      " << p->level << "\n"; // ...
                 }
             }
           
               if,    ,
                  ,   -
             ,      ,  -
            ,     .
                7.2.8  
           
                     -
            ,       ,
                 . 
                   
              . :
           
             struct employee { employee* next;  char* name;  short department;
                 // ... virtual void print();
             };
           
             virtual ,     
             print()    ,     
                print()   -
           .             -
              .       
             ,     . :
           
             void employee::print() {
                 cout << e->name << "\t" << e->department << "\n";
                 // ...
             }
           
             ,  ,    
           ,       ,   
           ,        ,
              .      -
                ,   . :
           
             struct manager :  employee { employee* group; short level; // ...
                 void print();
             };
           
             void manager::print() {
                 employee::print(); cout  << "\t" << level << "\n";  //
                 ...
             }
            print_employee()   ,    
             print(),        
           :
           
             void f(employee* ll) {
                 for (; ll; ll=ll->next) ll->print();
             }
           
                   . -
           :
           
             main() {
                 employee e;  e.name = "."; e.department = 1234; e.next
                     = 0;
                 manager m; m.name = "."; e.department = 1234; m.level =
                     2; m.next = &e;
                 f(&m);
             }
           
           
           
             . 1234  2
             . 1234
           
             ,        ,  f() 
                     ,    
           manager  ! ,      -
             employee     . -
               (  )   
             .      -
               ,      
                  .    -
               ,     .
           
                    
           ::,     manager::print(), ,  
                .    manager::print()
              .    
               ,        :  
             virtual      inline (  -
             ),  ,     ::,  -
             inline-.        
                 ,  
                  .  
                      ,
                      
             .
                7.3  
           
              ,     ,    -
            ,        -
           .   ,     , -
               ,        ,      
            ,       .
                     ,
            ,     ,  -
           .      -  ,  
                       #include.
           ,   ,        
           .
           
                7.3.1 
           
                 slist   
           ,        ,    
               ,     -
           .     ent:
           
             typedef void* ent;
           
                ent ,  ,    
            .     slink:
           
             class slink { friend class slist; friend class slist_iterator;
                 slink* next; ent e; slink(ent a, slink* p) { e=a; next=p;}
             };
           
                   ent,     -
             slist:
           
             class slist { friend class slist_iterator;
                 slink* last; // last->next -   public:
                 int insert(ent a); //     int append(ent
                 a);  //     ent get(); //   -
                    void clear(); //   
           
                 slist() { last=0;  }  slist(ent  a)  {  last=new  slink(a,0);
                 last->next=last; } ~slist() { clear(); }
             };
                      ,
                 ,        
           ent',       .   , 
           slink'          slist',  
                  .
           
                7.3.2 
           
              slist    .  -
             -     , , , -
               get() -   .   
             #7.3.4.      slist.  
           ,           
                  append()  
           insert():
           
             int slist::insert(ent a) {
                 if (last) last->next = new slink(a,last->next);
                 else { last = new slink(a,0); last->next = last;
                 }
                 return 0;
             }
           
             int slist::append(ent a) {
                 if (last) last = last->next = new slink(a,last->next);
                 else { last = new slink(a,0); last->next = last;
                 }
                 return 0;
             }
           
             ent slist::get() {
                 if (last == 0) slist_handler("get fromempty list");
                                            //    
                 slink* f = last->next; ent r f->e; if (f == last)
                     last = 0; else
                     last->next = f->next; delete f; return f;
             }
              ,     slist_handler  (  
               #7.3.4).       
             ,       .   -
                :
           
             (*slist_handler)("get fromempty list");
           
            slist::clear(), ,     :
           
             void slist::clear() {
                 slink* l = last; if (l == 0) return; do {
                     slink* ll = l; l = l->next; delete ll;
                 } while (l!=last);
             }
           
              slist      ,  
                .    , 
           slist,   slink,    slist_iterator  , 
               .   ,    
           #6.8:
           
             class slist_iterator { slink* ce; slist* cs;
             public:
                 slist_iterator(slist& s) { cs = &s; ce = cs->last; }
           
                 ent operator()() {
                     //      0
                     //     ,   
                     ent ret = ce ?  (ce=ce->next)->e : 0; if (ce == cs->last)
                     ce= 0; return ret;
                 }
             };
                7.3.3   
           
               slist    .    
           ,        void*?   
           ,      slist      ,
                   .  
               ++.          
            ;  name -   
           
             struct name { char* string; // ...
             };
           
                 ,        
           .         e
           slist',        
             .     nlist,   
              slist:
           
             #include "slist.h"
             #include "name.h"
           
             struct nlist : slist { void insert(name* a) { slist::insert(a); }
                 void append(name* a) { slist::append(a);  }  name*  get()  {}
                 nlist(name* a) : (a) {}
             };
           
                    slist  ,
                  .   nlist - 
            ,      slist.    
              ent  void*,     -
             name*,       
            (#2.3.4).
           
                  ,   -
            :
           
             struct classdef  {  nlist  friends;  nlist  constructors;   nlist
                 destructors;  nlist members; nlist operators; nlist virtuals;
                 // ... void add_name(name*); classdef(); ~classdef();
             };
                   :
           
             void classdef::add_name(name* n) {
                 if (n->is_friend()) { if (find(&friends,n))
                         error("friend redeclared");
                             // friend 
                     else if (find(&members,n))  error("friend  redeclared  as
                         member");
                             // friend   member
                     else friends.append(n);
                 }
                 if (n->is_operator()) operators.append(n);
                 // ...
             }
           
            is_operator()    is_friend()    
           name.  find()   :
           
             int find(nlist* ll, name* n) {
                 slist_iterator ff(*(slist*)ll);  ent  p;  while ( p=ff() ) if
                 (p==n) return 1; return 0;
             }
           
                    ,    
           slist_iterator  nlist.   ,   
           nlist',   #7.3.5.  nlist , , 
           :
           
             void print_list(nlist* ll, char* list_name) {
                 slist_iterator count(*(slist*)ll);  name* p; int n = 0; while
                 (  count()  )  n++;  cout  <<  list_name  <<  "\n"  <<  n  <<
                 "members\n";   slist_iterator   print(*(slist*)ll);  while  (
                 p=(name*)print() ) cout << p->string << "\n";
             }
                7.3.4  
           
                 ,   ,    -
                slist   
           ( ++        ):
           
             [1]       
                
           
             [2]           
                  
           
             [3]   ,     slist 
           
             [4]   ,    -
                 .
           
                ,     -
           ,           
             .      -
            .
           
              ,     ,  .
                 ,    
                 slist.
           
              ,    ,  
                 (      
             / istream  ostream;   - -
             #8.4.2).  ,  ,    , 
                    ,  
                  .   ,   
                   .  
                  .
              ,    ,    -
           .  ,    ,   ,
             ,     .  ,
                        -
           .
           
              ,     ,
               ,   -
                 (#4.5),      
              .
           
              3   4     (   -
           ),     ,    .  
             ,   slist,   -
           ,    ,     ,  
               ,        
            ,  ,  ,  . :
           
             typedef void (*PFC)(char*);  //       extern
             PFC slist_handler; extern PFC set_slist_handler(PFC);
           
              set_slist_hanlder()    -
            .     
               ,     -
               cerr,         
           exit():
           
             #include "slist.h"
             #include <stream.h>
           
             void default_error(char* s) {
                 cerr << s << "\n"; exit(1);
             }
                     ,   
           ,    :
           
             PFC slist_handler = default_error;
           
             PFC set_slist_handler(PFC handler); {
                 PFC rr = slist_handler; slist_handler = handler; return rr;
             }
           
              ,   set_slist_hanlder()  
           slist_hanlder().       -
               .       
               ,      slist     
             ,     ,  -
           ,          .
           :
           
             { PFC old = set_slist_handler(my_handler);
           
                 // ,       slist
                 //     my_handler
           
                 set_slist_handler(old); // 
             }
           
                 , slist_hanlder   
                 slist,       
              .
                7.3.5  
           
             ,                  
           (classdef*,  int,  char*  ..)   ,      
            nlist:      slist.   
               (   ),     -
               "".   ,  -
             C  (#4.7   #.11.1),    
             .     -
              .
           
               ,    (generic)  slist, 
           gslist,      .     
                 <generic.h>:
           
             #include "slist.h"
           
             #ifndef GENERICH
             #include <generic.h>
             #endif
           
                 #ifndef  ,  -
           ,  <generic.h>       -
           . GENERICH   <generic.h>.
           
                 name2(),    <generic.h>  -
            ,     :
           
             #define gslist(type) name2(type,gslist)
             #define gslist_iterator(type) name2(type,gslist_iterator)
           
             , ,                  gslist()     
           gslist_iterator():
           
             #define gslistdeclare(type)                              \
             struct gslist(type) : slist { \ int insert(type a) \
                     { return slist::insert( ent(a) );  } \ int append(type a)
                 \
                     { return slist::append( ent(a) ); } \ type get() { return
                 type(  slist::get()   );   }   \   gslist(type)()   {   }   \
                 gslist(type)(type  a)  :  (ent(a))  {  }  \ ~gslist(type)() {
                 clear(); } \
             };                                                       \
                                                                      \
             struct gslist_iterator(type)     :     slist_iterator     {     \
                 gslist_iterator(type)(gslist(type)& a) \
                     : ( (slist&)s ) {}                               \
                 type operator()()       \        {        return        type(
                     slist_iterator::operator()() ); } \
             }
           
             \     ,    
             .      -
               , 
              nlist,   :
           
             #include "name.h"
           
             typedef name*  Pname;  declare(gslist,Pname);  //  
             gslist(Pname)
           
             gslist(Pname) nl; //   gslist(Pname)
           
              declare ()   <generic.h>.  -
                   ,    
           gslistdeclare,  .     declare 
              .      
               name*,   typedef.
           
                ,      
              .     
                   ,  -
             ,      .  gslist  
           #7.6.2.
                7.3.6  
           
              slist -   .   
               .    , -
                  ,    ,    
           .       ,      
             . ,     :
           
             #include "slist.h"
           
             class iqueue : slist {
                            // sizeof(int)<=sizeof(void*)
             public:
                 void put(int a) {  slist::append((void*)a);  }  int  det()  {
                 return int(slist::get()); } iqueue() {}
             };
           
                           
           :       (
            ),     int,        
              ,  iqueue.       
           .     -  ,   , 
                :
           
             #include "slist.h"
           
             class stack : slist { public:
                 slist::insert; slist::get; stack() {} stack(ent a) : (a) {}
             };
           
                    "  
           ":
           
             #include "stack.h"
           
             class cp : stack { public:
                 void push(char* a) { slist::insert(a); } char* pop() { return
                 (char*)slist::get(); } nlist() {}
             };
                7.4   
           
                       -
            .       
                .      
                     -
           .     ,      
                  ,  -
               ,        ,      
           -.
           
                      -
             ,      .  -
              ,    -
            .  ,     slist,   ,
            ,    slink,    .
               ,       -
            ,   ,        -
              .     next     
              ,  ,     
            slink.     ,        olink  
             next,    olist,   
               olink.   olist  
             ,    olink.  "o"  -
              ,    ,     -
                 olist:
           
             struct olink { olink* next;
             };
           
            olist    slist.       ,
                olist    olink
           :
           
             class olist { olink* last;
             public:
                 void insert(olink* p);  void append(olink* p);  olink* get();
                 // ...
             };
           
                olink  name:
           
             class name : public olink {
                 // ...
             };
           
                ,      -
                 .
             ,   olist,    .   , 
              ,    olink'.    
                 , 
            olist. :
           
             void f() {
                 olist ll;  name nn;  ll.insert(&nn); //  &nn  name*
                 pn = (name*)ll.get(); //  
             }
           
            :    ,        
           olist    :
           
             class onlist : public olist {
                 // ...
                 name* get() { return (name*)olist::get(); }
             };
           
              name       olist.  
            ,   ,   ,   ,   
            ,   .  ,     shape
                   . -
            ,       slist   
            olist,     .  
                    -
               .
           
                7.5  
           
                .   ,   
              .     -
            .      . ,
                ,    
           ,     .   ,    
           . ,      
             ,       
            ,       
           .      --
               -.        ,  
                  
           .        ,
               (      -
           ),        ( -
            ).
                7.6  
           
                     -
             .          
           :
           
             [1]  :     
                ,  ;      
                ,
           
             [2]  :      -
                          
                
           
             [3]  :  , -
                   ,  ,   .
           
                      (  -
               ).          
                     -
           ,          -
           ,          .  
              .    , 
                ,   
              .        
           ,         ,
               .   -
                   - -
           ,        .
                7.6.1  
           
                      C ( 
            ++),      .  -
             ,      :
             C (  ,   , -
                   ..),    
           ,      -
              ..  ,  ,  -
                C ,    -
           ,       ++    -
           .
           
                  ,    -
               put_point()  put_line(),  
                point:
           
             //  screen.h
           
             const XMAX=40, YMAX=24;
           
             struct point { int x,y;  point() {} point(int a,  int b)  {  x=a;
                 y=b; }
             };
           
             overload put_point;  extern void put_point(int a,  int b); inline
             void put_point(point p) { put_point(p.x,p.y); }
           
             overload put_line;  extern  void put_line(int,  int,  int,  int);
             inline void put_line(point a, point b)
                 { put_line(a.x,a.y,b.x,b.y); }
           
             extern void screen_init();  extern void screen_refresh();  extern
             void screen_clear();
           
             #include <stream.h>
                  put   -
              screen_init(),      
                   screen_refresh().  
            ,   ""  ("refresh")  
                    -
           .       :
           
             #include "screen.h"
             #include <stream.h>
           
             enum color { black='*', white=' ' };
           
             char screen[XMAX][YNAX];
           
             void screen_init() {
                 for (int y=0; y<YMAX; y++) for (int x=0; x<XMAX; x++)
                         screen[x][y] = white;
             }
           
              ,      :
           
             inline int on_screen(int a, int b) {
                 return 0<=a && a<XMAX && 0<=b && b<YMAX;
             }
           
             void put_point(int a, int b) {
                 if (on_screen(a,b)) screen[a][b] = black;
             }
                  put_line():
           
             void put_line(int x0, int y0, int x1, int y1)
             /*
                    (x0,y0)  (x1,y1).    b(x-x0) +
                 a(y-y0) = 0.   abs(eps),   eps  =  2*(b(x-x0)+
                 a(y-y0)). . Newman and Sproull: ``Principles of Interactive
                 Computer Graphics'' McGraw-Hill, New York, 1979, pp 33-44.
             */
             { register dx = 1;  int a = x1 - x0;  if (a < 0) dx = -1, a = -a;
                 register dy = 1; int b = y1 - y0; if (b < 0) dy = -1, b = -b;
                 int two_a = 2*a;  int two_b = 2*b;  int xcrit = -b  +  two_a;
                 register eps = 0; for (;;) {
                     put_point(x0,y0); if(x0==x1 && y0==y1) break;  if(eps  <=
                     xcrit) x0 += dx,  eps += two_b;  if(eps>=a || a<=b) y0 +=
                     dy, eps -= two_a;
                 }
             }
           
                    :
           
             void screen_clear() { screen_init(); } // 
           
             void screen_refresh() //  {
                 for (int y=YMAX-1;  0<=y; y--) { //   for (int x=0;
                     x<XMAX; x++) //  
                         cout.put(screen[x][y]); cout.put('\n');
                 }
             }
           
              ostream::put()      -
           ;  ostream::operator<<()     .  
               ,     
             ,     .
                7.6.2  
           
                   (shape).    -
             ,     (    )
              (,   ),  ,
                    
           ,   shape:
           
             struct shape { shape() { shape_list.append(this); }
           
                 virtual point  north()  {return point(0,0);} //  virtual
                 point south() {return point(0,0);} //  virtual point east()
                 {return  point(0,0);} //  virtual point neast() {return
                 point(0,0);} // - virtual point  seast()  {return
                 point(0,0);} // -
           
                 virtual void draw() {};  //  virtual void move(int,
                 int) {}; // 
             };
           
                  ,       
           move(),        draw().  
              ,    -
           ,          (
           ).         ,
              ,      .    
                       
             .   shape::shape()  
               shape_list.     gslist,   ,
                , 
            #7.3.5.       :
           
             typedef shape* sp; declare(gslist,sp);
           
             typedef gslist(sp)    shape_lst;    typedef   gslist_iterator(sp)
             sp_iterator;
           
            shape_list   :
           
             shape_lst shape_list;
           
                   ,      -
           .       ,  -
             .    ,   
           :   .
              :
           
             class line : public shape {
             /*
                   'w'  'e' north()   ``    
                       ''
             */
                 point w,e; public:
                 point north() { return point((w.x+e.x)/2,e.y<w.y?w.y:e.y); }
           
                 point south() { return point((w.x+e.x)/2,e.y<w.y?e.y:w.y); }
           
                 void move(int a,  int b) { w.x += a;  w.y += b; e.x += a; e.x
                     += b; }
                 void draw() { put_line(w,e); }
           
                 line(point a, point b) { w = a; e = b; } line(point a, int l)
                     { w = point(a.x+l-1,a.y); e = a; }
             };
           
              rectangle:
           
             class rectangle : public shape {
             /*
                 nw ---- n ---- ne
                 | |
                 | |
                 w c e
                 | |
                 | |
                 sw ---- s ---- se
             */
                 point sw,ne; public:
                 point north()  {  return  point((sw.x+ne.x)/2,ne.y);  } point
                 south() { return point((sw.x+ne.x)/2,sw.y); } point neast() {
                 return ne;  } point swest() { return sw;  } void move (int a,
                 int b)
                     { sw.x+=a;  sw.y+=b;  ne.x+=a;  ne.y+=b;  }  void draw();
                 rectangle(point, point);
             };
                 .    - -
                :
           
             rectangle::rectangle(point a, point b); {
                 if (a.x <= b.x) { {
                         sw = a; ne = b;
                     }
                     else { sw = point(a.x,b.y); ne = point(b.x,a.y);
                     }
                 }
                 else { if (a.y <= b.y) {
                         sw = point(b.x,a.y); ne = point(a.x,b.y);
                     }
                     else { sw = b; ne = a;
                     }
                 }
             }
           
             ,    :
           
             void rectangle::draw(); {
                 point nw(sw.x,ne.y);  point  se(ne.x,sw.y);  put_line(nw,ne);
                 put_line(ne,se); put_line(se,sw); put_line(sw,nw);
             }
           
                    
             . :
           
             void shape_refresh();  //    void stack(shape*  p,
             shape* q); //  p   q
           
                 ,    -
           .       .   ,  
              ,   :
           
             void shape_refresh() {
                 screen_clear(); sl_iterator next(shape_list); shape* p; while
                 ( p=next() ) p->draw(); screen_refresh();
             }
            ,  ,     ().  
               ,  ,  south()   
             north() :
           
             void stack(shape* q, shape* p) //  p   q {
                 point n    =    p->north();    point    s    =    q->south();
                 q->move(n.x-s.x,n.y-s.y+1);
             }
           
               ,        -
             ,     ,  
                 ,   -
            ,     .   
                    -
                 .
           
                7.6.3  
           
                .   -
            myshape (      ),      -
               ,      .  
            myshape:
           
             #include "shape.h"
           
             class myshape :  public rectangle { line* l_eye;  //    
                 line* r_eye; //   line* mouth; // 
             public:
                 myshape(point, point); void draw(); void move(int, int);
             };
           
                -     ,    
            myshape:
           
             myshape::myshape(point a, point b) : (a,b) {
                 int ll     =     neast().x-swest().x+1;     int     hh      =
                 neast().y-swest().y+1; l_eye = new line(
                     point(swest().x+2,swest().y+hh*3/4),2); r_eye = new line(
                     point(swest().x+ll-4,swest().y+hh*3/4),2); mouth   =  new
                 line(
                     point(swest().x+2,swest().y+hh/4),ll-4);
             }
                                 
           shape_refresh(),          
            myshape,    .    -
                   myshape.
                .    -
           ,       draw():
           
             void myshape::draw() {
                 rectangle::draw(); put_point(point(
                     (swest().x+neast().x)/2,(swest().y+neast().y)/2));
             }
           
           myshape      -
            rectangle    l_eye,  r_eye   mouth  (
           ,    ):
           
             void myshape::move() {
                 rectangle::move(); l_eye->move(a,b);        r_eye->move(a,b);
                 mouth->move(a,b);
             }
           
              ,  ,       -
           :
           
             main() {
                 shape* p1 = new rectangle(point(0,0),point(10,10)); shape* p2
                 =    new    line(point(0,15),17);    shape*    p3    =    new
                 myshape(point(15,10),point(27,18));          shape_refresh();
                 p3->move(-10,-10);         stack(p2,p3);        stack(p1,p2);
                 shape_refresh(); return 0;
             }
                ,      shape_refresh()  
           stack()    ,    ,
              (,   ,  )   -
           .
           
                ***********
                * *
                * *
                * *
                * *
                * *
                * *
                * *
                * *
                * *
                ***********
             *****************
               *************
               * *
               * ** ** *
               * *
               * * *
               * *
               * ********* *
               * *
               *************
           
                7.7  
           
                 slist,   ,  
                       
               slink.    slink  -     
           ,      ,  
                 .    
               ,     
           #5.5.6.    slink    new  -
              delete   slist,   
               .
           
                    this,
                      
            ,     this   -
              ,    
           .         this,   
             ,     
           . :
           
             #include <stream.h>
           
             struct base { base(); };
           
             struct derived : base { derived(); }
           
             base::base() {
                 cout << "\tbase 1:  this=" << int(this) << "\n";  if (this ==
                 0) this = (base*)27;  cout << "\tbase 2:  this=" << int(this)
                 << "\n";
             }
             derived::derived() {
                 cout <<  "\tderived  1:  this=" << int(this) << "\n";  this =
                 (this == 0) ?  (derived*)43 :  this;  cout <<  "\tderived  2:
                 this=" << int(this) << "\n";
             }
           
             main() { cout << "base b;\n";  base b;  cout << "new base  b;\n";
             new base; cout << "derived d;\n"; derived d; cout << "new derived
             d;\n"; new derived; cout << "at the end\n";
           
             }
           
            
           
             base b; base 1: this=2147478307 base 2: this=2147478307
             new base; base 1: this=0 base 2: this=27
             derived d;  derived 1:  this=2147478306 base  1:  this=2147478306
                     base 2: this=2147478306 derived 1: this=2147478306
             new derived;  derived 1:  this=0 base 1:  this=43 base 2: this=43
                     derived 1: this=43
             at the end
           
                      
             this,      ,   
              .  -   -
              this, ,   
           this      *.
           
           
           *  ,     . , 
                 (  -  .)    
            derived::derived()  :
           
             if (this == 0) this = (derived*)43;
           
            ,   d    base::base() 
           .       ,  ,
           ,   ,   . (. )
                7.8 
           
             1. (*1) 
           
                  class base { public:
                      virtual void iam() { cout << "base\n"; }
                  };
           
                  base       iam() ("
                "),      .  
                      iam().   -
                     base*   iam() -
                  .
           
             2. (*2)    (#7.6.1)   
                 .
           
             3. (*2)      triangle ()   circle
                ().
           
             4. (*2)  ,   ,  
                ,    " "  -
                 .
           
             5. (*2)       ,    line  
                rectangle  .
           
             6. (*2)      ,  
                   .
           
             7. (*2)      ,  
                    .  -
                       ,    
                    ,     -
                 .
           
             8. (*2)      .
           
             9. (*4)  ,        
                 (     ).   
                  X,            X::X(X&),   X::~X()
                X::operator=(X&).
             10. (*5)         -
                ,  . : <task.h>.  
                -  ,       .  
                 task - .    task   
                       (  
                  task::save()    task::restore()),      
                  .    
                   ,     task.  ,
                   ,      -
                 .      -
                      ().   
                 ,     .
                    task::delay(),    ""
                  .       
                 task -     ,    -
                  .     . 
                   queue ().    ,
                        .   
                    .      
                 ,     ?
                                      8 
           
              ++     /.      
           .          -
            .       -
           /    ,    , -
                ,    -
                ,        
            ,   .    
                 <stream.h>.      
           ,           ,  
              .
                                     8.1 
           
                  /  -
                  -
           .   /  
                .   ++ -
               ,   , 
                     .  -
           ,  /   , , 
             ,    ,      .
                 ,      
                  /-
                /   
            .
           
             ++  ,      -
                  ,    
           .      ,   
           /  ++       ++    
             ,    . -
              /      -
              .
           
              / <stream.h>    -
                    
             .      /,   -
               UNIX,      -
             /     
             ,        -
           .         -
                    
            .
                      -
                      -
                 . :
           
             put(cerr,"x = ");  // cerr -        put(cerr,x);
             put(cerr,"\n");
           
                  ,      put  -
              .      
           .     .    <<
            " "       -
                . :
           
             cerr << "x = " << x << "\n";
           
            cerr -    .  ,   x -
            int   123,       -
              
           
             x = 123
           
              . ,  X  
             complex    (1,2.4),  
               cerr
           
             x = (1,2.4)
           
                 ,    x  -
            <<,       <<   -
           .
                8.2 
           
                      -
                 ,      
                  
           .
           
                8.2.1   
           
              ostream      << (" ")
               :
           
             class ostream {
                 // ...
             public:
                 ostream& operator<<(char*);   ostream&  operator<<(int  i)  {
                 return *this<<long(i);  } ostream& operator<<(long); ostream&
                 operator<<(double);
           
                 ostream& put(char);
             };
           
              operator<<    ostream,   
            ,        ostream. -
           :
           
             cerr << "x = " << x;
           
            x  int,   :
           
             (cerr.operator<<("x = ")).operator<<(x);
           
              ,  ,      -
             ,      :
            .   operator<<,    int, 
           ,   int     long. 
            , int      double. -
             ostream::operator<<(int)      -
           .         
           ostream::put(char),    ostream::operator<<(int)    
           .
           
                8.2.2    
           
                :
           
             class complex { double re, im;
             public:
                 complex(double r = 0, double i = 0) { re=r; im=i; }
           
                 friend double real(complex& a) { returna.re;  } friend double
                 real(complex& a) { returna.re; }
           
                 friend complex  operator+(complex,  complex);  friend complex
                 operator-(complex,       complex);       friend       complex
                 operator*(complex,       complex);       friend       complex
                 operator/(complex, complex); // ...
             };
              <<    complex   :
           
             ostream& operator<<(ostream&s, complex z) {
                 return s << "(" << real(z) << "," << imag(z) << ")";
             }
           
               ,    :
           
             complex x(1,2);
             // ...
             cout << "x = " << x << "\n";
           
             
           
             x = (1,2)
           
                    
                    ostream,    
             (),     . 
           ,     ,     ostream
               ,      
               .    ,  
                    .  
                   ostream    -
            .
           
                8.2.3   
           
               ,     ,
                .   <<?
           
                   (#6.2). -
                  ,     -
           ,  ,   ,  
               .   , =    
            (),   cout=a=b  cout=(a=b).
           
                 <  >,    "-
           "  ""      ,   
            /      -
           .  , "<"       
           ",",       :
           
             cout < x , y , z;
           
                     -
           .
              <<   >>      ,   -
              ,       ""  "",
              <<  ,      
                 . :
           
             cout << "a*b+c=" << a*b+c << "\n";
           
             ,   ,    
             ,   . :
           
             cout << "a^b|c=" << (a^b|c) << "\n";
           
                     :
           
             cout << "a<<b=" << (a<<b) << "\n";
           
              ++     ,   ,  '\n'
             (  10,      
           ASCII), 
           
             cout << "x = " << x << '\n';
           
             10,      .   -
              ,      (
                ASKII):
           
             #define sp << " "
             #define ht << "\t"
             #define nl << "\n"
           
                :
           
             cout << "x = " << x nl;
           
                   ostream::put(char) 
           chr(int) (.  #8.2.4).        
               ,   .
           
              :
           
             cout << x << " " << y << " " << z << "\n"; cout << "x = " << x <<
             ", y = " << y << "\n";
           
                  -      
           ,       . 
                  :
           
             cout << x sp << y sp << z nl; cout << "x = " << x
                  << ", y = " << y nl;
                8.2.4  
           
              <<      ,    
                     -
             .      -
             ,         
           ,    .   ()
             ,        -
           .
           
             char* oct(long,  int=0);  //       char*
             dec(long,  int=0);  //     char* hex(long,
             int=0); //   char* chr(int, int=0);
             //  char* str(char*, int=0); // 
           
                  ,     -
             ;         
           (),  . :
           
             cout << "dec(" << x
                  << ") = oct(" << oct(x,6)
                  << ") = hex(" << hex(x,4)
                  << ")";
           
              x==15,    :
           
             dec(15) = oct( 17) = hex( f);
           
                   :
           
             char* form(char* format ...);
           
           cout<<form()         
            C printf()*. form()  ,   -
                  ,    
               -   format. -
                 :   , -
                 ,    -
           ,         
           .      
           %. :
           
             cout<<form("there were %d members present",no_of_members);
           
              %d ,   no_of_members   
           int       -
            .  no_of_members==127,   :
           
             there were 127 members present
           
           
             *  ,    , -  
                printf().  (.  )
                  
              .  %  :
           
             -   ,    -
                     ;
           
             d   ,   .  -
                    ,    ,  -
                      ( ,    
                  )      ;
                     ,     -
                    ;
           
             .  ,      
                 ;
           
             d   ,   ,  
                         e
                 f     ;
           
             *           *.
                           -
                ;
           
             h   h;    ,     d,
                o, x  y    ;
           
             l   h;    ,     d,
                o, x  y    ;
           
             % ,      %, 
                    ;
           
             c ,  ,        -
                .      :
           
                d      ;
           
                o      ;
           
                x      ;
           
                f   float  double    
                      [-]ddd.ddd,   ,    d  
                      ,     
                     .   ,   ; 
                          0,     
                           ;
           
                e  float  double     
                      [-]d.ddde+dd,      
                     ,   ,     -
                     ,         ;
                       ,   ;
           
                g  float  double      d,f  
                     e,        
                      ;
                c   ,   ;
           
                s     (  ),  
                                
                      ,      , -
                       ;      ,
                         ;
           
                u          -
                     .
           
                     
                  ;        
                 ,        
                .
           
                :
           
             char* src_file_name;  int  line;  char* line_format = "\n#line %d
             \"%s\"\n";    //...    cout    <<    "int    a;\n";    cout    <<
             form(line_format,line,src_file_name); cout << "int b;\n";
           
            
           
             int a;
           
             #line 13 "++/main.c"
             int b;  form()    ,   -
             
            .  , ,     -
              /  (core dump):
           
             char x;
             // ...
             cout<<form("bad input char: %s",x);
           
             ,       ,   -
              C.       
            printf().
           
                         ,
              ,   -
           *   ,       
                   -
           ,      -
           ,   ,       .. ,
                  .   ,   
               ,    -
             ,     
            ,    ,  -
             oct(), hex()  .. :
           
             class complex { float re,im;
             public:
                 // ...
                 char* string(char* format) { return form(format,re,im); }
             };
             // ...
             cout << z.string("(%.3f,%.3f)");
           
                  ,    form(),  hex() 
           ..,        -
           ,      ,  
             ,   .  
            .
                8.2.5   
           
                     virtual.    
            shape,     (#1.18):
           
             class shape {
                 // ...
             public:
                 // ...
                 virtual void draw(ostream& s); //  "this"  "s"
             };
           
             class circle : public shape { int radius;
             public:
                 // ...
                 void draw(ostream&);
             };
           
              ,           
            ,        , -
                .
           
                     -
           ,  <<  :
           
             ostream& operator<<(ostream& s, shape* p) {
                 p->draw(s); return s;
             }
           
              next -     #7.3.3,   
             :
           
             while ( p = next() ) cout << p;
                8.3   
           
                 .    -
              cin,     cout  -
               cerr.       
              .
           
                8.3.1   
           
             ostream  :
           
             class ostream {
                 // ...
                 ostream(streambuf* s);  //            
                 ostream(int  fd);  //     ostream(int size,
                 char* p); //   
             };
           
                    -    .
           streambuf - ,  ;    #8.6, 
             filebuf,  streambuf  .  filebuf -
               streambuf.
           
                 cout   cerr,    -
                   /,  
           :
           
                 //    
             char cout_buf[BUFSIZE]
           
                 //  "filebuf"    
                 //    UNIX'   1 ( )
             filebuf cout_file(1,cout_buf,BUFSIZE);
           
                 //  ostream,   
             ostream cout(&cout_file);
           
             char cerr_buf[1];
           
                 //  0,  , 
                 // UNIX'   2 ( )
             filebuf cerr_file(2,cerr_buf,0);
           
             ostream cerr(&cerr_file);
           
                 ostream    #8.3.3 
           #8.5.
           
                8.3.2   
           
               ostream      
            ostream::flush():
           
             ostream::~ostream() {
                 flush(); // 
             }
           
                . :
           
             cout.flush();
                8.3.3  
           
               ,     , -
                       -
           .    <stream.h>   cin,
           cout  cerr,    (   )     -
               .  , , ,  -
             ,      ,  -
              :
           
             #include <stream.h>
           
             void error(char* s, char* s2) {
                 cerr << s << " " << s2 << "\n"; exit(1);
             }
           
             main(int argc, char* argv[]) {
                 if (argc != 3) error("  ","");
           
                 filebuf f1; if (f1.open(argv[1],input) == 0)
                     error("      ",argv[1]);  istream
                 from(&f1);
           
                 filebuf f2; if (f2.open(argv[2],output) == 0)
                     error("     ",argv[2]);  ostream
                 to(&f2);
           
                 char ch; while (from.get(ch)) to.put(ch);
           
                 if (!from.eof() !!  to.bad()) error("    -
                     ","");
             }
           
                 ostream  
             ,      : (1) 
             (      filebuf);
           (2)               (    
                  filebuf::open());  ,
           ,  (3)   ostream  filebuf   .
              .
           
                    :
           
             enum open_mode { input, output };
           
              filebuf::open()  0,     
                .     
           ,     output,   .
                ,     -
             (.  #8.4.2).     
             .
           
                      ,   
            ,     ,    
              .      
             ( ).      ,  
                , .  8-
           10.
           
                8.3.4  
           
                . :
           
             cout = cerr;
           
                  ,   
              .        ,  
                cin      -  
           (  .  #3.1.6)
           
                8.4 
           
               .   istream,  -
             >> (" ")     
           .  operator>>    , -
            .
           
                8.4.1   
           
              istream  :
           
             class istream {
                 // ...
             public:
                 istream& operator>>(char*);      //            istream&
                 operator>>(char&);  //    istream&  operator>>(short&);
                 istream&    operator>>(int&);   istream&   operator>>(long&);
                 istream& operator>>(float&); istream& operator>>(double&); //
                 ...
             };
           
                  :
           
             istream& istream::operator>>(char& c); {
                     //  
                 int a;
                     //      "a"
                 c = a;
             }
           
                      C,   
           isspase()   ,     <ctype.h> (, -
           ,   ,     ).
                   get():
           
             class istream {
                 // ...
                 istream& get(char& c);  // char istream& get(char* p,  int n,
                 int ='\n'); // 
             };
           
                  ,    .
            istream::get(char)      ; -
            istream::get    n    ,  -
             p.      -
              (,    ),  
                .      -
           ,        .    
               get      n ,   
              ,  '\n'     .
                ,    
           . :
           
             cin.get(buf,256,'\t');
           
              buf   256 ,    -
            ('\t'),       get.    -
            ,     cin,  '\t'.
           
                  <ctype.h>     
           ,       :
           
             int isalpha(char)  //  'a'..'z'  'A'..'Z'  int  isupper(char)  //
             'A'..'Z' int  islower(char)  //  'a'..'z'  int  isdigit(char)  //
             '0'..'9'  int  isxdigit(char)  //  '0'..'9' 'a'..'f' 'A'..'F' int
             isspase(char) // ' ' '\t'   
                                  //  
             int iscntrl(char) //  
                                  // (ASCII 0..31  127)
             int ispunct(char) // :     int
             isalnum(char) // isalpha() | isdigit() int isprint(char) // -
             : ascii ' '..'-' int isgraph(char) // isalpha() | isdigit()
             | ispunct() int isascii(char c) { return 0<=c && c<=127; }
           
                isascii()   ,   
                    .  
            , 
           
             (('a'<=c && c<='z') || ('A'<=c && c<='Z')) // 
           
                  (   -
             EBCDIC     ),  
              ,    :
           
             isalpha(c)
                8.4.2  
           
               (istream  ostream)       
           ,         -
                     -
           .
           
                    :
           
             enum stream_state { _good, _eof, _fail, _bad };
           
                _good   _eof,     
            .    _good,     
              ,       .
            ,     ,   -
              _good,   .  
               v,       ,
            v    (  ,  v
               ,      
           istream  ostream).     _fail  _bad 
                  -
            .    _fail ,    
               .    _bad    
           .
           
                  :
           
             switch (cin.rdstate()) { case _good:
                 //    cin  
                 break; case _eof:
                 //  
                 break; case _fail:
                 //    
                 // ,   
                 break; case _bad:
                 // ,  cin 
                 break;
             }
           
                z ,      <<
            >>,     :
           
             while (cin>>z) cout << z << "\n";
           
             ,  z -  ,       -
                      (
           ,    )  .
           
                  ,   
            ,       ( , -
              )    _good.    ,  
               istream,   
           cin>>z.  ,      -
           ,    .    -
              (#6.3.2).
                       
              ,        
           ,       ,    .
           ,      ,    -
               .    /  ,
              ++  (  )  
               (       
           ),        -
                /.
           
                8.4.3  ,  
           
                      ,
            ,    ,     , 
               . :
           
             istream& operator>>(istream& s, complex& a)
             /*
                    complex; "f"  float:
                 f ( f ) ( f , f )
             */
             { double re = 0, im = 0; char c = 0;
           
                 s >> c; if (c == '(') {
                     s >> re >> c;  if (c == ',') s >> im >> c;  if (c != ')')
                     s.clear(_bad); //  state
                 }
                 else { s.putback(c); s >> re;
                 }
           
                 if (s) a = complex(re,im); return s;
             }
           
               ,         ,  
                   .  
            c ,       -
            '('  ,     . 
              ,    a -
                ,    .
           
                  clear() (),  
                     -
              _good.  _good      
            istream::clear(),   ostream::clear().
           
                  .   ,   ,
           ,           
           (   Snobol  Icon),    ,   
             .     , , -
              ,    -
                     -
            .
                8.4.4   
           
             ,  istream,     ostream,  -
           :
           
             class istream {
                 // ...
                 istream(streambuf* s,  int sk =1, ostream* t =0); istream(int
                 size,  char*  p,  int  sk  =1);  istream(int  fd,  int sk =1,
                 ostream* t =0);
             };
           
              sk ,      .  -
            t ()      ostream,    
            istream.  ,  cin   cout;   ,
             ,        ,  cin
           
           
             cout.flush(); //   
           
                istream::tie()   ( ,
             tie(0))  ostream   istream. :
           
             int y_or_n(ostream& to, istream& from)
             /*
                  "to",    "from"
             */
             { ostream* old = from.tie(&to); for (;;) {
                     cout <<   "   Y    N:  ";  char  ch  =  0;  if
                     (!cin.get(ch)) return 0;
           
                     if (ch != '\n') { //    char ch2 =
                         0; while (cin.get(ch2) && ch2 != '\n') ;
                     }
                     switch (ch) { case 'Y': case 'y': case '\n':
                         from.tie(old); //    tie  return
                         1;
                     case 'N':
                     case 'n':
                         from.tie(old); //    tie  return
                         0;
                     default:
                         cout << ",   : ";
                     }
                 }
             }
           
                  (      
           ),         
           .          .  y_or_n()
               ,   .
           
                                       
           istream::putback(char).     "  -
           "   .
                8.5   
           
               ,   /,  -
            ,    istream  ostream. , 
              ,    ,    
                    -
            :
           
             void word_per_line(char v[], int sz)
             /*
                  "v"  "sz"     
             */
             { istream ist(sz,v);  //  istream  v char  b2[MAX];  //
                    while (ist>>b2) cout << b2 << "\n";
             }
           
                        
             .
           
                ostream     ,   
              :
           
             char* p = new  char[message_size];  ostream  ost(message_size,p);
             do_something(arguments,ost); display(p);
           
              ,  do_something,     ost, -
            ost    ..    
           .      , -
            ost         ,    
                _fail.  ,  ,  display  
             ""  .       
            ,     ,   -
                     ,
                 .  ,
             ost      -    
             .
           
                8.6 
           
                /      -
           ,          -
              .  ,  ostream, -
              ,    , -
               ostream,     .     
           ,           
              (     
           ostream).         -
           ,     ostream  ,   .  
           ,       ,  -
           .   ,      
             .         
                 ,    
                    
           .
                 <stream.h>  :
           
             struct streambuf { //   
           
                 char* base; //   char* pptr; //  -
                   char  char*  qptr;  //    char char*
                 eptr; //     char alloc; // , -
                    new
           
                     //  :
                     //  EOF    0   
                 virtual int overflow(int c =EOF);
           
                     //  
                     //  EOF     ,
                     //   char
                 virtual int underflow();
           
                 int snextc() //   char {
                     return (++qptr==pptr) ? underflow() : *qptr&0377;
                 }
           
                 // ...
           
                 int allocate() //    
           
                 streambuf() { /* ...  */} streambuf(char* p,  int l) { /* ...
                 */} ~streambuf() { /* ... */}
             };
           
              ,     , 
               ,      
            (  )     inline-
           .       -
               overflow()  underflow(). -
           :
           
             struct filebuf : public streambuf {
           
                 int fd; //   char opened; //  
           
                 int overflow(int c =EOF); int underflow();
           
                 // ...
           
                     //  :
                     //   ,   0,
                     //     "this"
                 filebuf* open(char *name, open_mode om); int close() { /* ...
                 */ }
           
                 filebuf() {  opened  =  0;  } filebuf(int nfd) { /* ...  */ }
                 filebuf(int nfd,  char* p,  int l) :  (p,l) {  /*  ...  */  }
                 ~filebuf() { close(); }
             };
             int filebuf::underflow() //    fd {
                 if (!opened || allocate()==EOF) return EOF;
           
                 int count = read(fd,  base, eptr-base); if (count < 1) return
                 EOF;
           
                 qptr = base; pptr = base + count; return *qptr & 0377;
             }
           
                8.7 
           
                ,    / <stream.h>  
              ,    , 
            .       .    
           "   "  inline-,  -
                   - -
                 .     (,   
           ..)      .   ,  
                /,    
             .
           
                8.8 
           
             1. (*1.5)       ,    
                         
                .
           
             2. (*1.5)   name_and_address (__).  -
                         <<      >>.       
                name_and_address.
           
             3. (*2)         -
                   .    -  y_or_n() 
                #8.4.4. : ,    ,  , -
                 ,  ,     ..  
                   .
           
             4. (*1.5)  ,    (1)     
                 , (2)  , (3)    , (4) 
                ,        ++  
                 ,  (5)   , (6)  
                  , (7)   , (8) 
                   ,  (9)   .
           
             5. (*4)            /  C
                (<stdio.h>)     /  ++
                (<stream.h>).
           
             6. (*4)          /  ++
                (<stream.h>)      /  C
                (<stdio.h>).
           
             7. (*4)    C  ++ ,   
                  .
             8. (*2)  ,    []   -
                     .
           
             9. (*3)   8,   ,   []   
                 ,    . : ,  [] -
                  " ",   
                     ,   -
                  char       .
           
             10. (*2)   9,    []  -
                  ,   .
           
             11. (*3)    ,    -
                 10.
           
             12. (*3.5)        -
                  .      
                   printf.     -
                         -
                 .         
                 istream.
           
             13. (*4)  ( )  ,   
                .
